diff --git a/bash_it.sh b/bash_it.sh index bfa6664b..ee6957b9 100644 --- a/bash_it.sh +++ b/bash_it.sh @@ -4,29 +4,17 @@ # Reload Library alias reload='source ~/.bash_profile' -# Load the framework - -# Load colors first so they can be use in base theme -source "${BASH}/themes/colors.theme.bash" -source "${BASH}/themes/base.theme.bash" - -# Library -LIB="${BASH}/lib/*.bash" -for config_file in $LIB -do - if [ -e "${config_file}" ]; then - source $config_file - fi -done +# Only set $BASH_IT if it's not already set +[ -z "$BASH_IT" ] && export BASH_IT=$HOME/.bash_it # Load enabled aliases, completion, plugins for file_type in "aliases" "completion" "plugins" do - if [ ! -d "${BASH}/${file_type}/enabled" ] + if [ ! -d "${BASH_IT}/${file_type}/enabled" ] then - continue + continue fi - FILES="${BASH}/${file_type}/enabled/*.bash" + FILES="${BASH_IT}/${file_type}/enabled/*.bash" for config_file in $FILES do if [ -e "${config_file}" ]; then @@ -36,13 +24,13 @@ do done # Load any custom aliases that the user has added -if [ -e "${BASH}/aliases/custom.aliases.bash" ] +if [ -e "${BASH_IT}/aliases/custom.aliases.bash" ] then - source "${BASH}/aliases/custom.aliases.bash" + source "${BASH_IT}/aliases/custom.aliases.bash" fi # Custom -CUSTOM="${BASH}/custom/*.bash" +CUSTOM="${BASH_IT}/custom/*.bash" for config_file in $CUSTOM do if [ -e "${config_file}" ]; then @@ -50,6 +38,16 @@ do fi done +# Load colors first so they can be use in base theme +source "${BASH_IT}/themes/colors.theme.bash" +source "${BASH_IT}/themes/base.theme.bash" + +# library +LIB="${BASH_IT}/lib/*.bash" +for config_file in $LIB +do + source $config_file +done unset config_file if [[ $PROMPT ]]; then diff --git a/install.sh b/install.sh index f84c097b..a80a7499 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -BASH="$HOME/.bash_it" +BASH_IT="$HOME/.bash_it" cp $HOME/.bash_profile $HOME/.bash_profile.bak @@ -30,24 +30,24 @@ done function load_all() { file_type=$1 - [ ! -d "$BASH/$file_type/enabled" ] && mkdir "$BASH/${file_type}/enabled" - ln -s $BASH/${file_type}/available/* "${BASH}/${file_type}/enabled" + [ ! -d "$BASH_IT/$file_type/enabled" ] && mkdir "$BASH_IT/${file_type}/enabled" + ln -s $BASH_IT/${file_type}/available/* "${BASH_IT}/${file_type}/enabled" } function load_some() { file_type=$1 - for file in `ls $BASH/${file_type}/available` + for file in `ls $BASH_IT/${file_type}/available` do - if [ ! -d "$BASH/$file_type/enabled" ] + if [ ! -d "$BASH_IT/$file_type/enabled" ] then - mkdir "$BASH/$file_type/enabled" + mkdir "$BASH_IT/$file_type/enabled" fi while true do read -p "Would you like to enable the ${file%.*.*} $file_type? [Y/N] " RESP case $RESP in [yY]) - ln -s "$BASH/$file_type/available/$file" "$BASH/$file_type/enabled" + ln -s "$BASH_IT/$file_type/available/$file" "$BASH_IT/$file_type/enabled" break ;; [nN]) diff --git a/lib/appearance.bash b/lib/appearance.bash index f7235118..28a131a4 100644 --- a/lib/appearance.bash +++ b/lib/appearance.bash @@ -8,6 +8,6 @@ export GREP_COLOR='1;33' export LSCOLORS='Gxfxcxdxdxegedabagacad' # Load the theme -if [[ $BASH_THEME ]]; then - source "$BASH/themes/$BASH_THEME/$BASH_THEME.theme.bash" -fi \ No newline at end of file +if [[ $BASH_IT_THEME ]]; then + source "$BASH_IT/themes/$BASH_IT_THEME/$BASH_IT_THEME.theme.bash" +fi diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index 95f481e9..34d99ac1 100644 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -7,11 +7,11 @@ export PATH=$PATH:~/.gem/ruby/1.8/bin:/opt/nginx/sbin # Path to the bash it configuration -export BASH=$HOME/.bash_it +export BASH_IT=$HOME/.bash_it # Lock and Load a custom theme file # location /.bash_it/themes/ -export BASH_THEME='bobby' +export BASH_IT_THEME='bobby' # Your place for hosting Git repos. I use this for private repos. export GIT_HOSTING='git@git.domain.com' @@ -40,4 +40,4 @@ export TODO="t" #export VCPROMPT_EXECUTABLE=~/.vcprompt/bin/vcprompt # Load Bash It -source $BASH/bash_it.sh +source $BASH_IT/bash_it.sh diff --git a/themes/base.theme.bash b/themes/base.theme.bash index feee64e8..05db36e5 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -6,15 +6,16 @@ SCM_THEME_PROMPT_CLEAN=' ✓' SCM_THEME_PROMPT_PREFIX=' |' SCM_THEME_PROMPT_SUFFIX='|' -GIT='git' +SCM_GIT='git' SCM_GIT_CHAR='±' -HG='hg' +SCM_HG='hg' SCM_HG_CHAR='☿' -SVN='svn' +SCM_SVN='svn' SCM_SVN_CHAR='⑆' +SCM_NONE='NONE' SCM_NONE_CHAR='○' RVM_THEME_PROMPT_PREFIX=' |' @@ -24,76 +25,85 @@ VIRTUALENV_THEME_PROMPT_PREFIX=' |' VIRTUALENV_THEME_PROMPT_SUFFIX='|' function scm { - if [[ -d .git ]]; then SCM=$GIT - elif [[ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]]; then SCM=$GIT - elif [[ -d .hg ]]; then SCM=$HG - elif [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$HG - elif [[ -d .svn ]]; then SCM=$SVN - else SCM='NONE' + if [[ -d .git ]]; then SCM=$SCM_GIT + elif [[ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]]; then SCM=$SCM_GIT + elif [[ -d .hg ]]; then SCM=$SCM_HG + elif [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG + elif [[ -d .svn ]]; then SCM=$SCM_SVN + else SCM=$SCM_NONE fi } -function scm_char { +function scm_prompt_char { if [[ -z $SCM ]]; then scm; fi - [[ $SCM == $GIT ]] && echo $SCM_GIT_CHAR && return - [[ $SCM == $HG ]] && echo $SCM_HG_CHAR && return - [[ $SCM == $SVN ]] && echo $SCM_SVN_CHAR && return - echo $SCM_NONE_CHAR + if [[ $SCM == $SCM_GIT ]]; then SCM_CHAR=$SCM_GIT_CHAR + elif [[ $SCM == $SCM_HG ]]; then SCM_CHAR=$SCM_HG_CHAR + elif [[ $SCM == $SCM_SVN ]]; then SCM_CHAR=$SCM_SVN_CHAR + else SCM_CHAR=$SCM_NONE_CHAR + fi +} + +function scm_prompt_vars { + scm + scm_prompt_char + SCM_DIRTY=0 + SCM_STATE='' + [[ $SCM == $SCM_GIT ]] && git_prompt_vars && return + [[ $SCM == $SCM_HG ]] && hg_prompt_vars && return + [[ $SCM == $SCM_SVN ]] && svn_prompt_vars && return } function scm_prompt_info { - if [[ -z $SCM ]]; then scm; fi - [[ $SCM == $GIT ]] && git_prompt_info && return - [[ $SCM == $HG ]] && hg_prompt_info && return - [[ $SCM == $SVN ]] && svn_prompt_info && return + scm + scm_prompt_char + SCM_DIRTY=0 + SCM_STATE='' + [[ $SCM == $SCM_GIT ]] && git_prompt_info && return + [[ $SCM == $SCM_HG ]] && hg_prompt_info && return + [[ $SCM == $SCM_SVN ]] && svn_prompt_info && return } -# Stolen from Steve Losh -# left in for backwards-compatibility -function prompt_char { - char=$(scm_char); - echo -e "$char" -} - -function git_prompt_info { +function git_prompt_vars { if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then - state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_DIRTY=1 + SCM_STATE=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else - state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_DIRTY=0 + SCM_STATE=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} fi - prefix=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - suffix=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - ref=$(git symbolic-ref HEAD 2> /dev/null) || return - - echo -e "$prefix${ref#refs/heads/}$state$suffix" + SCM_PREFIX=${GIT_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + SCM_SUFFIX=${GIT_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + local ref=$(git symbolic-ref HEAD 2> /dev/null) + SCM_BRANCH=${ref#refs/heads/} + SCM_CHANGE=$(git rev-parse HEAD 2>/dev/null) } -function svn_prompt_info { +function svn_prompt_vars { if [[ -n $(svn status 2> /dev/null) ]]; then - state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_DIRTY=1 + SCM_STATE=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else - state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_DIRTY=0 + SCM_STATE=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} fi - prefix=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - suffix=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - ref=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return - - [[ -z $ref ]] && return - echo -e "$prefix$ref$state$suffix" + SCM_PREFIX=${SVN_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + SCM_SUFFIX=${SVN_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + SCM_BRANCH=$(svn info 2> /dev/null | awk -F/ '/^URL:/ { for (i=0; i<=NF; i++) { if ($i == "branches" || $i == "tags" ) { print $(i+1); break }; if ($i == "trunk") { print $i; break } } }') || return + SCM_CHANGE=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) } -function hg_prompt_info() { +function hg_prompt_vars { if [[ -n $(hg status 2> /dev/null) ]]; then - state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + SCM_DIRTY=1 + SCM_STATE=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else - state=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + SCM_DIRTY=0 + SCM_STATE=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} fi - prefix=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} - suffix=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} - branch=$(hg summary 2> /dev/null | grep branch | awk '{print $2}') - changeset=$(hg summary 2> /dev/null | grep parent | awk '{print $2}') - - echo -e "$prefix$branch:${changeset#*:}$state$suffix" + SCM_PREFIX=${HG_THEME_PROMPT_PREFIX:-$SCM_THEME_PROMPT_PREFIX} + SCM_SUFFIX=${HG_THEME_PROMPT_SUFFIX:-$SCM_THEME_PROMPT_SUFFIX} + SCM_BRANCH=$(hg summary 2> /dev/null | grep branch | awk '{print $2}') + SCM_CHANGE=$(hg summary 2> /dev/null | grep parent | awk '{print $2}') } function rvm_version_prompt { @@ -109,3 +119,28 @@ function virtualenv_prompt { echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" fi } + +# backwards-compatibility +function git_prompt_info { + git_prompt_vars + echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" +} + +function svn_prompt_info { + svn_prompt_vars + echo -e "$SCM_PREFIX$SCM_BRANCH$SCM_STATE$SCM_SUFFIX" +} + +function hg_prompt_info() { + hg_prompt_vars + echo -e "$SCM_PREFIX$SCM_BRANCH:${SCM_CHANGE#*:}$SCM_STATE$SCM_SUFFIX" +} + +function scm_char { + scm_prompt_char + echo -e "$SCM_CHAR" +} + +function prompt_char { + scm_char +}