From 1a83a4d1939a6e182664bd78dac6f6296103f5d4 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 31 May 2011 13:19:20 -1000 Subject: [PATCH 01/17] Added hawaii50 theme --- themes/hawaii50/hawaii50.theme.bash | 118 ++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 themes/hawaii50/hawaii50.theme.bash diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash new file mode 100644 index 00000000..a81cc0b9 --- /dev/null +++ b/themes/hawaii50/hawaii50.theme.bash @@ -0,0 +1,118 @@ +#!/bin/basORANGEh + +# Colors +ORANGE='\e[0;33m' +GREY='\e[1:37m' + +DEFAULT_COLOR='\[${white}\]' + +USER_COLOR='\[${purple}\]' +SUPERUSER_COLOR='\[${red}\]' +MACHINE_COLOR=$ORANGE +DIRECTORY_COLOR='\[${bold_green}\]' + +VE_COLOR='\[${red}\]' +RVM_COLOR='\[${purple}\]' + +# SCM prompts +SCM_THEME_PROMPT_DIRTY=' ${bold_red}✗${normal}' +SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' + +# Max length of PWD to display +MAX_PWD_LENGTH=20 + +# Max length of Git Hex to display +MAX_GIT_HEX_LENGTH=5 + +# Use http://geoff.greer.fm/lscolors/ + +# Displays the current virtualenv information +function curr_virtualenv_info() { + [ ! -z "$VIRTUAL_ENV" ] && echo "`basename $VIRTUAL_ENV`" +} + +# Displays the current rvm information w/gemset +function curr_rvm_info() { + local ruby_version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') + local ruby_gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') + + if [ "$ruby_version" != "" ]; then + [ "$ruby_gemset" != "" ] && ruby_gemset="@$ruby_gemset" + echo "$ruby_version$ruby_gemset" + fi +} + +# Displays using ... +function virtual_info() { + local virtual_env_info=$(curr_virtualenv_info) + local rvm_info=$(curr_rvm_info) + local prompt="using" + + # If no virtual info, just return + [ "$virtual_env_info" == "" -a "$rvm_info" == "" ] && return + + # If virtual_env info present, append to prompt + [ "$virtual_env_info" != "" ] && prompt="$prompt virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}" + + if [ "$rvm_info" != "" ] + then + [ "$virtual_env_info" != "" ] && prompt="$prompt," + prompt="$prompt rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}" + fi + echo $prompt +} + + +# SCM information +function scm_info() { + SCM_CHAR=$(scm_char) + [ "$SCM_CHAR" == "$SCM_NONE_CHAR" ] && return + local prompt="on" + [ "$SCM_CHAR" == "$SCM_GIT_CHAR" ] && echo "$prompt$(parse_git_info)" && return +} + +# Parse git info +function parse_git_info() { + 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} + else + 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 + rawhex=$(git rev-parse HEAD 2>/dev/null) || return + + echo -e "$prefix${ref#refs/heads/} (${rawhex:0:$MAX_GIT_HEX_LENGTH})$state$suffix" +} + +# Displays last X characters of pwd +function limited_pwd() { + + # Replace $HOME with ~ if possible + RELATIVE_PWD=${PWD/#$HOME/\~} + + local offset=$((${#RELATIVE_PWD}-$MAX_PWD_LENGTH)) + + if [ $offset -gt "0" ] + then + local truncated_symbol="..." + TRUNCATED_PWD=${RELATIVE_PWD:$offset:$MAX_PWD_LENGTH} + echo "${truncated_symbol}/${TRUNCATED_PWD#*/}" + else + echo "${RELATIVE_PWD}" + fi +} + +# Displays the current prompt +function prompt() { + + local UC=$USER_COLOR + [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR + + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR} $(virtual_info) $(scm_info) \$ " + PS2='> ' + PS4='+ ' +} + +PROMPT_COMMAND=prompt From 06d71ab59141b536a9a0bdd22791a002fa98def5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 31 May 2011 16:10:30 -1000 Subject: [PATCH 02/17] Updated git prompt Started hg prompt --- themes/hawaii50/hawaii50.theme.bash | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index a81cc0b9..987153b3 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -24,6 +24,12 @@ MAX_PWD_LENGTH=20 # Max length of Git Hex to display MAX_GIT_HEX_LENGTH=5 +GIT_THEME_PROMPT_PREFIX=' |git:' +GIT_THEME_PROMPT_SUFFIX='|' + +HG_THEME_PROMPT_PREFIX=' |hg:' +HG_THEME_PROMPT_SUFFIX='|' + # Use http://geoff.greer.fm/lscolors/ # Displays the current virtualenv information @@ -62,13 +68,14 @@ function virtual_info() { echo $prompt } - # SCM information function scm_info() { SCM_CHAR=$(scm_char) [ "$SCM_CHAR" == "$SCM_NONE_CHAR" ] && return local prompt="on" [ "$SCM_CHAR" == "$SCM_GIT_CHAR" ] && echo "$prompt$(parse_git_info)" && return + [ "$SCM_CHAR" == "$SCM_SVN_CHAR" ] && echo "$prompt$(parse_svn_info)" && return + [ "$SCM_CHAR" == "$SCM_HG_CHAR" ] && echo "$prompt$(parse_hg_info)" && return } # Parse git info @@ -83,9 +90,24 @@ function parse_git_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return rawhex=$(git rev-parse HEAD 2>/dev/null) || return - echo -e "$prefix${ref#refs/heads/} (${rawhex:0:$MAX_GIT_HEX_LENGTH})$state$suffix" + echo "$prefix${ref#refs/heads/}=#${rawhex:0:$MAX_GIT_HEX_LENGTH}$state$suffix" } +# Parse hg info +function parse_hg_info() { + if [[ -n $(hg status --no-color 2> /dev/null| awk '$1 == "?" { print "?" } $1 = "?" { print "!" }' | sort | uniq | head -c1) ]]; then + state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + else + 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 branch 2> /dev/null | awk '{print $1}') + + echo "$prefix$branch$state$suffix" +} + + # Displays last X characters of pwd function limited_pwd() { From aa2f1cbeb7141a24d154de15b35f3f51914f285a Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 31 May 2011 18:41:07 -1000 Subject: [PATCH 03/17] Added hg dirty/clean modifier --- themes/hawaii50/hawaii50.theme.bash | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 987153b3..656649b4 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -32,6 +32,16 @@ HG_THEME_PROMPT_SUFFIX='|' # Use http://geoff.greer.fm/lscolors/ +# Override function scm +function scm { + if [[ -d .git ]]; then SCM=$GIT + elif [[ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]]; then SCM=$GIT + elif [[ -n "$(hg summary 2> /dev/null)" ]]; then SCM=$HG + elif [[ -d .svn ]]; then SCM=$SVN + else SCM='NONE' + fi +} + # Displays the current virtualenv information function curr_virtualenv_info() { [ ! -z "$VIRTUAL_ENV" ] && echo "`basename $VIRTUAL_ENV`" @@ -90,21 +100,22 @@ function parse_git_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return rawhex=$(git rev-parse HEAD 2>/dev/null) || return - echo "$prefix${ref#refs/heads/}=#${rawhex:0:$MAX_GIT_HEX_LENGTH}$state$suffix" + echo "$prefix${ref#refs/heads/}:${rawhex:0:$MAX_GIT_HEX_LENGTH}$state$suffix" } # Parse hg info function parse_hg_info() { - if [[ -n $(hg status --no-color 2> /dev/null| awk '$1 == "?" { print "?" } $1 = "?" { print "!" }' | sort | uniq | head -c1) ]]; then + if [[ -n $(hg status 2> /dev/null) ]]; then state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else 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 branch 2> /dev/null | awk '{print $1}') + branch=$(hg summary 2> /dev/null | grep branch | awk '{print $2}') + changeset=$(hg summary 2> /dev/null | grep parent | awk '{print $2}') - echo "$prefix$branch$state$suffix" + echo "$prefix${branch}:${changeset#*:}$state$suffix" } From 2a6d1da317e4aafab8cfcd2ca8702379d9a8ac06 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 31 May 2011 19:03:28 -1000 Subject: [PATCH 04/17] Updated parse_svn_info --- themes/hawaii50/hawaii50.theme.bash | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 656649b4..16ecf07c 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -30,6 +30,9 @@ GIT_THEME_PROMPT_SUFFIX='|' HG_THEME_PROMPT_PREFIX=' |hg:' HG_THEME_PROMPT_SUFFIX='|' +SVN_THEME_PROMPT_PREFIX=' |svn:' +SVN_THEME_PROMPT_SUFFIX='|' + # Use http://geoff.greer.fm/lscolors/ # Override function scm @@ -118,6 +121,20 @@ function parse_hg_info() { echo "$prefix${branch}:${changeset#*:}$state$suffix" } +# Parse svn info +function parse_svn_info() { + if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then + state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + else + 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 + revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) + [[ -z $ref ]] && return + echo -e "$prefix$ref:$revision$state$suffix" +} # Displays last X characters of pwd function limited_pwd() { From 09dfe7552c4b9538df85fabef855a5c7e941f5f2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 31 May 2011 19:17:10 -1000 Subject: [PATCH 05/17] Added ip address (only good for a mac) :D ) --- themes/hawaii50/hawaii50.theme.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 16ecf07c..1a9281df 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -9,6 +9,7 @@ DEFAULT_COLOR='\[${white}\]' USER_COLOR='\[${purple}\]' SUPERUSER_COLOR='\[${red}\]' MACHINE_COLOR=$ORANGE +IP_COLOR=$MACHINE_COLOR DIRECTORY_COLOR='\[${bold_green}\]' VE_COLOR='\[${red}\]' @@ -35,6 +36,10 @@ SVN_THEME_PROMPT_SUFFIX='|' # Use http://geoff.greer.fm/lscolors/ +function ip { + echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') +} + # Override function scm function scm { if [[ -d .git ]]; then SCM=$GIT @@ -160,7 +165,7 @@ function prompt() { local UC=$USER_COLOR [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR} $(virtual_info) $(scm_info) \$ " + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR} $(virtual_info) $(scm_info) \$ " PS2='> ' PS4='+ ' } From 9bd5b5498498f2623ede326fde33afdf87456f86 Mon Sep 17 00:00:00 2001 From: Ryan Kanno Date: Tue, 31 May 2011 21:23:33 -1000 Subject: [PATCH 06/17] Added color to the scm prompt --- themes/hawaii50/hawaii50.theme.bash | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 1a9281df..bf493efc 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -15,6 +15,9 @@ DIRECTORY_COLOR='\[${bold_green}\]' VE_COLOR='\[${red}\]' RVM_COLOR='\[${purple}\]' +SCM_COLOR=$ORANGE +REF_COLOR='\[${purple}\]' + # SCM prompts SCM_THEME_PROMPT_DIRTY=' ${bold_red}✗${normal}' SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' @@ -25,13 +28,13 @@ MAX_PWD_LENGTH=20 # Max length of Git Hex to display MAX_GIT_HEX_LENGTH=5 -GIT_THEME_PROMPT_PREFIX=' |git:' +GIT_THEME_PROMPT_PREFIX=" |${SCM_COLOR}git${DEFAULT_COLOR}:" GIT_THEME_PROMPT_SUFFIX='|' -HG_THEME_PROMPT_PREFIX=' |hg:' +HG_THEME_PROMPT_PREFIX=" |${SCM_COLOR}hg${DEFAULT_COLOR}:" HG_THEME_PROMPT_SUFFIX='|' -SVN_THEME_PROMPT_PREFIX=' |svn:' +SVN_THEME_PROMPT_PREFIX=" |${SCM_COLOR}svn${DEFAULT_COLOR}:" SVN_THEME_PROMPT_SUFFIX='|' # Use http://geoff.greer.fm/lscolors/ @@ -108,7 +111,7 @@ function parse_git_info() { ref=$(git symbolic-ref HEAD 2> /dev/null) || return rawhex=$(git rev-parse HEAD 2>/dev/null) || return - echo "$prefix${ref#refs/heads/}:${rawhex:0:$MAX_GIT_HEX_LENGTH}$state$suffix" + echo "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${rawhex:0:$MAX_GIT_HEX_LENGTH}$state$suffix" } # Parse hg info @@ -123,7 +126,7 @@ function parse_hg_info() { branch=$(hg summary 2> /dev/null | grep branch | awk '{print $2}') changeset=$(hg summary 2> /dev/null | grep parent | awk '{print $2}') - echo "$prefix${branch}:${changeset#*:}$state$suffix" + echo "$prefix${REF_COLOR}${branch}${DEFAULT_COLOR}:${changeset#*:}$state$suffix" } # Parse svn info @@ -138,7 +141,7 @@ function parse_svn_info() { 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 revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) [[ -z $ref ]] && return - echo -e "$prefix$ref:$revision$state$suffix" + echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix" } # Displays last X characters of pwd From 0611f861bc15752e3d5c407ce6bb1a7cef180355 Mon Sep 17 00:00:00 2001 From: Ryan Kanno Date: Tue, 31 May 2011 21:38:41 -1000 Subject: [PATCH 07/17] Changed color schemes Completely removed prefix/suffix for scm --- themes/hawaii50/hawaii50.theme.bash | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index bf493efc..378512fa 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -10,10 +10,10 @@ USER_COLOR='\[${purple}\]' SUPERUSER_COLOR='\[${red}\]' MACHINE_COLOR=$ORANGE IP_COLOR=$MACHINE_COLOR -DIRECTORY_COLOR='\[${bold_green}\]' +DIRECTORY_COLOR='\[${green}\]' -VE_COLOR='\[${red}\]' -RVM_COLOR='\[${purple}\]' +VE_COLOR='\[${cyan}\]' +RVM_COLOR='\[${cyan}\]' SCM_COLOR=$ORANGE REF_COLOR='\[${purple}\]' @@ -28,16 +28,9 @@ MAX_PWD_LENGTH=20 # Max length of Git Hex to display MAX_GIT_HEX_LENGTH=5 -GIT_THEME_PROMPT_PREFIX=" |${SCM_COLOR}git${DEFAULT_COLOR}:" -GIT_THEME_PROMPT_SUFFIX='|' - -HG_THEME_PROMPT_PREFIX=" |${SCM_COLOR}hg${DEFAULT_COLOR}:" -HG_THEME_PROMPT_SUFFIX='|' - -SVN_THEME_PROMPT_PREFIX=" |${SCM_COLOR}svn${DEFAULT_COLOR}:" -SVN_THEME_PROMPT_SUFFIX='|' - -# Use http://geoff.greer.fm/lscolors/ +# Removed prefix/suffix +SCM_THEME_PROMPT_PREFIX=" " +SCM_THEME_PROMPT_SUFFIX="" function ip { echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') @@ -73,11 +66,12 @@ function curr_rvm_info() { function virtual_info() { local virtual_env_info=$(curr_virtualenv_info) local rvm_info=$(curr_rvm_info) - local prompt="using" # If no virtual info, just return [ "$virtual_env_info" == "" -a "$rvm_info" == "" ] && return + local prompt=" using" + # If virtual_env info present, append to prompt [ "$virtual_env_info" != "" ] && prompt="$prompt virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}" @@ -86,14 +80,14 @@ function virtual_info() { [ "$virtual_env_info" != "" ] && prompt="$prompt," prompt="$prompt rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}" fi - echo $prompt + echo "$prompt" } # SCM information function scm_info() { SCM_CHAR=$(scm_char) [ "$SCM_CHAR" == "$SCM_NONE_CHAR" ] && return - local prompt="on" + local prompt=" on" [ "$SCM_CHAR" == "$SCM_GIT_CHAR" ] && echo "$prompt$(parse_git_info)" && return [ "$SCM_CHAR" == "$SCM_SVN_CHAR" ] && echo "$prompt$(parse_svn_info)" && return [ "$SCM_CHAR" == "$SCM_HG_CHAR" ] && echo "$prompt$(parse_hg_info)" && return @@ -168,7 +162,7 @@ function prompt() { local UC=$USER_COLOR [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR} $(virtual_info) $(scm_info) \$ " + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_info)$(scm_info) \$ " PS2='> ' PS4='+ ' } From 0df98ca8e915910b3b17fbafdb3726ee8acc0f87 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 1 Jun 2011 11:22:22 -1000 Subject: [PATCH 08/17] Various theme cleanup (removing vars, extras) --- themes/hawaii50/hawaii50.theme.bash | 40 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 378512fa..4933123c 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -1,6 +1,32 @@ -#!/bin/basORANGEh +#!/bin/bash -# Colors +# This theme was obviously inspired a lot by +# - Demula theme +# +# which in itself was inspired by : +# +# - Ronacher's dotfiles (mitsuhikos) - http://github.com/mitsuhiko/dotfiles/tree/master/bash/ +# - Glenbot - http://theglenbot.com/custom-bash-shell-for-development/ +# - My extravagant zsh - http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/ +# - Monokai colors - http://monokai.nl/blog/2006/07/15/textmate-color-theme/ +# - Bash_it modern theme +# +# Things theme supports: +# - shortended directory +# - hg, svn detection +# - virtualenv, rvm +# +# Screenshot: +# +# by Ryan Kanno +# +# And yes, we code out in Hawaii. :D +# +# Note: I also am really new to this bash scripting game, so if you see things +# that are flat out wrong, or if you think of something neat, just send a pull +# request. + +# COLORS ====================================================================== ORANGE='\e[0;33m' GREY='\e[1:37m' @@ -9,18 +35,19 @@ DEFAULT_COLOR='\[${white}\]' USER_COLOR='\[${purple}\]' SUPERUSER_COLOR='\[${red}\]' MACHINE_COLOR=$ORANGE -IP_COLOR=$MACHINE_COLOR +IP_COLOR=$ORANGE DIRECTORY_COLOR='\[${green}\]' VE_COLOR='\[${cyan}\]' RVM_COLOR='\[${cyan}\]' -SCM_COLOR=$ORANGE REF_COLOR='\[${purple}\]' # SCM prompts SCM_THEME_PROMPT_DIRTY=' ${bold_red}✗${normal}' SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' +SCM_THEME_PROMPT_PREFIX=" " +SCM_THEME_PROMPT_SUFFIX="" # Max length of PWD to display MAX_PWD_LENGTH=20 @@ -28,10 +55,7 @@ MAX_PWD_LENGTH=20 # Max length of Git Hex to display MAX_GIT_HEX_LENGTH=5 -# Removed prefix/suffix -SCM_THEME_PROMPT_PREFIX=" " -SCM_THEME_PROMPT_SUFFIX="" - +# FUNCS ======================================================================= function ip { echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') } From f3787fdc2e6faa3aa9b670c77f3ab57154efd931 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 1 Jun 2011 11:33:41 -1000 Subject: [PATCH 09/17] Added comments to theme --- themes/hawaii50/hawaii50.theme.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 4933123c..a0343a04 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -1,6 +1,7 @@ #!/bin/bash - +# # This theme was obviously inspired a lot by +# # - Demula theme # # which in itself was inspired by : @@ -11,10 +12,11 @@ # - Monokai colors - http://monokai.nl/blog/2006/07/15/textmate-color-theme/ # - Bash_it modern theme # -# Things theme supports: -# - shortended directory -# - hg, svn detection -# - virtualenv, rvm +# Hawaii50 theme supports : +# +# - configurable directory length +# - hg, svn, git detection (I work in all of them) +# - virtualenv, rvm + gemsets # # Screenshot: # @@ -24,7 +26,9 @@ # # Note: I also am really new to this bash scripting game, so if you see things # that are flat out wrong, or if you think of something neat, just send a pull -# request. +# request. This probably only works on a Mac - as some functions are OS +# specific like getting ip, etc. +# # COLORS ====================================================================== ORANGE='\e[0;33m' From dcb0ddec2f343f8a685b0cd2795454abb5853555 Mon Sep 17 00:00:00 2001 From: Ryan Kanno Date: Tue, 7 Jun 2011 08:25:45 -1000 Subject: [PATCH 10/17] Added comments Added imgur screenshot --- themes/hawaii50/hawaii50.theme.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index a0343a04..ac3bb592 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -18,7 +18,7 @@ # - hg, svn, git detection (I work in all of them) # - virtualenv, rvm + gemsets # -# Screenshot: +# Screenshot: http://i.imgur.com/4IAMJ.png # # by Ryan Kanno # @@ -60,6 +60,8 @@ MAX_PWD_LENGTH=20 MAX_GIT_HEX_LENGTH=5 # FUNCS ======================================================================= + +# TODO: Should check with `uname` and use ip addr function ip { echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') } From c7fcf206480046d4cc9e0f031ea9826b91a0adbf Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 8 Jun 2011 10:20:04 -1000 Subject: [PATCH 11/17] Updated scm function to include `hg root` to check for Mercurial Removed scm function from hawaii50.theme.bash --- themes/base.theme.bash | 1 + themes/hawaii50/hawaii50.theme.bash | 10 ---------- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 70876622..948427ac 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -24,6 +24,7 @@ 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' fi diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index ac3bb592..4fb8b1db 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -66,16 +66,6 @@ function ip { echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') } -# Override function scm -function scm { - if [[ -d .git ]]; then SCM=$GIT - elif [[ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]]; then SCM=$GIT - elif [[ -n "$(hg summary 2> /dev/null)" ]]; then SCM=$HG - elif [[ -d .svn ]]; then SCM=$SVN - else SCM='NONE' - fi -} - # Displays the current virtualenv information function curr_virtualenv_info() { [ ! -z "$VIRTUAL_ENV" ] && echo "`basename $VIRTUAL_ENV`" From 0713fdc031012899bdb02d7e49fd7362af2a3d97 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 8 Jun 2011 11:32:50 -1000 Subject: [PATCH 12/17] Added virtualenv_prompt to base.theme.bash (modeled after rvm_prompt) Removed virtualenv/rvm from hawaii50 theme --- themes/base.theme.bash | 10 ++++++++++ themes/hawaii50/hawaii50.theme.bash | 30 ++++++++++------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 948427ac..d6be1544 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -20,6 +20,9 @@ SCM_NONE_CHAR='○' RVM_THEME_PROMPT_PREFIX=' |' RVM_THEME_PROMPT_SUFFIX='|' +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 @@ -85,3 +88,10 @@ function rvm_version_prompt { echo -e "$RVM_THEME_PROMPT_PREFIX$rvm$RVM_THEME_PROMPT_SUFFIX" fi } + +function virtualenv_prompt { + if which virtualenv &> /dev/null; then + virtualenv=$([ ! -z "$VIRTUAL_ENV" ] && echo "`basename $VIRTUAL_ENV`") || return + echo -e "$VIRTUALENV_THEME_PROMPT_PREFIX$virtualenv$VIRTUALENV_THEME_PROMPT_SUFFIX" + fi +} diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 4fb8b1db..a8e1de27 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -50,8 +50,14 @@ REF_COLOR='\[${purple}\]' # SCM prompts SCM_THEME_PROMPT_DIRTY=' ${bold_red}✗${normal}' SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' -SCM_THEME_PROMPT_PREFIX=" " -SCM_THEME_PROMPT_SUFFIX="" +SCM_THEME_PROMPT_PREFIX=' ' +SCM_THEME_PROMPT_SUFFIX='' + +RVM_THEME_PROMPT_PREFIX='' +RVM_THEME_PROMPT_SUFFIX='' + +VIRTUALENV_THEME_PROMPT_PREFIX='' +VIRTUALENV_THEME_PROMPT_SUFFIX='' # Max length of PWD to display MAX_PWD_LENGTH=20 @@ -66,26 +72,10 @@ function ip { echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') } -# Displays the current virtualenv information -function curr_virtualenv_info() { - [ ! -z "$VIRTUAL_ENV" ] && echo "`basename $VIRTUAL_ENV`" -} - -# Displays the current rvm information w/gemset -function curr_rvm_info() { - local ruby_version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') - local ruby_gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') - - if [ "$ruby_version" != "" ]; then - [ "$ruby_gemset" != "" ] && ruby_gemset="@$ruby_gemset" - echo "$ruby_version$ruby_gemset" - fi -} - # Displays using ... function virtual_info() { - local virtual_env_info=$(curr_virtualenv_info) - local rvm_info=$(curr_rvm_info) + local virtual_env_info=$(virtualenv_prompt) + local rvm_info=$(rvm_version_prompt) # If no virtual info, just return [ "$virtual_env_info" == "" -a "$rvm_info" == "" ] && return From 28e2aeda4db35bfa58b9ccdcff87cf2c5d1eb5a1 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 8 Jun 2011 11:57:16 -1000 Subject: [PATCH 13/17] Refactored theme to remove scm_info and rename overridden functions --- themes/hawaii50/hawaii50.theme.bash | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index a8e1de27..3dc77bc6 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -59,6 +59,9 @@ RVM_THEME_PROMPT_SUFFIX='' VIRTUALENV_THEME_PROMPT_PREFIX='' VIRTUALENV_THEME_PROMPT_SUFFIX='' +SCM_PROMPT_PREFIX=' on' +SCM_PROMPT_SUFFIX='' + # Max length of PWD to display MAX_PWD_LENGTH=20 @@ -94,17 +97,13 @@ function virtual_info() { } # SCM information -function scm_info() { - SCM_CHAR=$(scm_char) - [ "$SCM_CHAR" == "$SCM_NONE_CHAR" ] && return - local prompt=" on" - [ "$SCM_CHAR" == "$SCM_GIT_CHAR" ] && echo "$prompt$(parse_git_info)" && return - [ "$SCM_CHAR" == "$SCM_SVN_CHAR" ] && echo "$prompt$(parse_svn_info)" && return - [ "$SCM_CHAR" == "$SCM_HG_CHAR" ] && echo "$prompt$(parse_hg_info)" && return +function h50_scm_prompt_info() { + local scm_prompt=$(scm_prompt_info) + [[ -n "$scm_prompt" ]] && echo -e "$SCM_PROMPT_PREFIX$scm_prompt$SCM_PROMPT_SUFFIX" } # Parse git info -function parse_git_info() { +function git_prompt_info() { 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} else @@ -119,7 +118,7 @@ function parse_git_info() { } # Parse hg info -function parse_hg_info() { +function hg_prompt_info() { if [[ -n $(hg status 2> /dev/null) ]]; then state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else @@ -134,7 +133,7 @@ function parse_hg_info() { } # Parse svn info -function parse_svn_info() { +function svn_prompt_info() { if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else @@ -172,7 +171,7 @@ function prompt() { local UC=$USER_COLOR [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_info)$(scm_info) \$ " + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_info)$(h50_scm_prompt_info) \$ " PS2='> ' PS4='+ ' } From 09bd0ef5d04660b33aa76ba96c916b3efe0032e8 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 8 Jun 2011 13:34:27 -1000 Subject: [PATCH 14/17] Um, what was I thinking. Removed SCM_PROMPT_PREFIX and custom scm_info. (No need for it). --- themes/hawaii50/hawaii50.theme.bash | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 3dc77bc6..946b808c 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -50,7 +50,7 @@ REF_COLOR='\[${purple}\]' # SCM prompts SCM_THEME_PROMPT_DIRTY=' ${bold_red}✗${normal}' SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' -SCM_THEME_PROMPT_PREFIX=' ' +SCM_THEME_PROMPT_PREFIX=' on ' SCM_THEME_PROMPT_SUFFIX='' RVM_THEME_PROMPT_PREFIX='' @@ -59,9 +59,6 @@ RVM_THEME_PROMPT_SUFFIX='' VIRTUALENV_THEME_PROMPT_PREFIX='' VIRTUALENV_THEME_PROMPT_SUFFIX='' -SCM_PROMPT_PREFIX=' on' -SCM_PROMPT_SUFFIX='' - # Max length of PWD to display MAX_PWD_LENGTH=20 @@ -96,12 +93,6 @@ function virtual_info() { echo "$prompt" } -# SCM information -function h50_scm_prompt_info() { - local scm_prompt=$(scm_prompt_info) - [[ -n "$scm_prompt" ]] && echo -e "$SCM_PROMPT_PREFIX$scm_prompt$SCM_PROMPT_SUFFIX" -} - # Parse git info function git_prompt_info() { if [[ -n $(git status -s 2> /dev/null |grep -v ^# |grep -v "working directory clean") ]]; then @@ -171,7 +162,7 @@ function prompt() { local UC=$USER_COLOR [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_info)$(h50_scm_prompt_info) \$ " + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_info)$(scm_prompt_info) \$ " PS2='> ' PS4='+ ' } From b96345e00c64dc2be94275f3d1b6f298bf6af378 Mon Sep 17 00:00:00 2001 From: Ryan Kanno Date: Thu, 9 Jun 2011 12:18:11 -1000 Subject: [PATCH 15/17] Added VIRTUAL_PROMPT_ENABLED FLAG Added -e to echo to interpret \ Updated bash conditionals to use [[]] --- themes/hawaii50/hawaii50.theme.bash | 73 +++++++++++++++++------------ 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 946b808c..6202eb4d 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -53,12 +53,20 @@ SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' SCM_THEME_PROMPT_PREFIX=' on ' SCM_THEME_PROMPT_SUFFIX='' +# rvm prompts RVM_THEME_PROMPT_PREFIX='' RVM_THEME_PROMPT_SUFFIX='' +# virtualenv prompts VIRTUALENV_THEME_PROMPT_PREFIX='' VIRTUALENV_THEME_PROMPT_SUFFIX='' +# virtual prompts +VIRTUAL_PROMPT_ENABLED=1 + +VIRTUAL_THEME_PROMPT_PREFIX=' using ' +VIRTUAL_THEME_PROMPT_SUFFIX='' + # Max length of PWD to display MAX_PWD_LENGTH=20 @@ -69,72 +77,76 @@ MAX_GIT_HEX_LENGTH=5 # TODO: Should check with `uname` and use ip addr function ip { - echo $(ifconfig en1 | grep "inet " | awk '{ print $2 }') + echo -e $(ifconfig en1 | grep "inet " | awk '{ print $2 }') } -# Displays using ... -function virtual_info() { +# Displays virtual info prompt (virtualenv/rvm) +function virtual_prompt_info() { local virtual_env_info=$(virtualenv_prompt) local rvm_info=$(rvm_version_prompt) + local virtual_prompt="" + + local prefix=${VIRTUAL_THEME_PROMPT_PREFIX} + local suffix=${VIRTUAL_THEME_PROMPT_SUFFIX} # If no virtual info, just return - [ "$virtual_env_info" == "" -a "$rvm_info" == "" ] && return - - local prompt=" using" + [[ -z "$virtual_env_info" && -z "$rvm_info" ]] && return # If virtual_env info present, append to prompt - [ "$virtual_env_info" != "" ] && prompt="$prompt virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}" + [[ -n "$virtual_env_info" ]] && virtual_prompt="virtualenv: ${VE_COLOR}$virtual_env_info${DEFAULT_COLOR}" - if [ "$rvm_info" != "" ] + if [[ -n "$rvm_info" ]] then - [ "$virtual_env_info" != "" ] && prompt="$prompt," - prompt="$prompt rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}" + [[ -n "$virtual_env_info" ]] && virtual_prompt="$virtual_prompt, " + virtual_prompt="${virtual_prompt}rvm: ${RVM_COLOR}$rvm_info${DEFAULT_COLOR}" fi - echo "$prompt" + echo -e "$prefix$virtual_prompt$suffix" } # Parse git info function git_prompt_info() { 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} + state=${GIT_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else - state=${GIT_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + 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 - rawhex=$(git rev-parse HEAD 2>/dev/null) || return + commit_id=$(git rev-parse HEAD 2>/dev/null) || return - echo "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${rawhex:0:$MAX_GIT_HEX_LENGTH}$state$suffix" + echo -e "$prefix${REF_COLOR}${ref#refs/heads/}${DEFAULT_COLOR}:${commit_id:0:$MAX_GIT_HEX_LENGTH}$state$suffix" } # Parse hg info function hg_prompt_info() { if [[ -n $(hg status 2> /dev/null) ]]; then - state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + state=${HG_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else - state=${HG_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + 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 "$prefix${REF_COLOR}${branch}${DEFAULT_COLOR}:${changeset#*:}$state$suffix" + echo -e "$prefix${REF_COLOR}${branch}${DEFAULT_COLOR}:${changeset#*:}$state$suffix" } # Parse svn info function svn_prompt_info() { if [[ -n $(svn status --ignore-externals -q 2> /dev/null) ]]; then - state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} + state=${SVN_THEME_PROMPT_DIRTY:-$SCM_THEME_PROMPT_DIRTY} else - state=${SVN_THEME_PROMPT_CLEAN:-$SCM_THEME_PROMPT_CLEAN} + 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 - revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) [[ -z $ref ]] && return + + revision=$(svn info 2> /dev/null | sed -ne 's#^Revision: ##p' ) + echo -e "$prefix${REF_COLOR}$ref${DEFAULT_COLOR}:$revision$state$suffix" } @@ -150,21 +162,24 @@ function limited_pwd() { then local truncated_symbol="..." TRUNCATED_PWD=${RELATIVE_PWD:$offset:$MAX_PWD_LENGTH} - echo "${truncated_symbol}/${TRUNCATED_PWD#*/}" + echo -e "${truncated_symbol}/${TRUNCATED_PWD#*/}" else - echo "${RELATIVE_PWD}" + echo -e "${RELATIVE_PWD}" fi } # Displays the current prompt function prompt() { + local UC=$USER_COLOR + [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - local UC=$USER_COLOR - [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR - - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_info)$(scm_prompt_info) \$ " - PS2='> ' - PS4='+ ' + if [[ $VIRTUAL_PROMPT_ENABLED == 1 ]]; then + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_prompt_info)$(scm_prompt_info) \$ " + else + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(scm_prompt_info) \$ " + fi + PS2='> ' + PS4='+ ' } PROMPT_COMMAND=prompt From 49f897ae0def7ef26fe68570726cfb3804bb75c3 Mon Sep 17 00:00:00 2001 From: Ryan Kanno Date: Thu, 9 Jun 2011 13:20:41 -1000 Subject: [PATCH 16/17] Changed ip function to use bash-it's func, parsing out 127.0.0.1 Attached public facing ip address to list --- themes/hawaii50/hawaii50.theme.bash | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index 6202eb4d..a86821c0 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -73,11 +73,14 @@ MAX_PWD_LENGTH=20 # Max length of Git Hex to display MAX_GIT_HEX_LENGTH=5 +# IP address +IP_SEPARATOR=', ' + # FUNCS ======================================================================= -# TODO: Should check with `uname` and use ip addr function ip { - echo -e $(ifconfig en1 | grep "inet " | awk '{ print $2 }') + myip=$(curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+') + echo -e "$(ips | sed -e :a -e '$!N;s/\n/${IP_SEPARATOR}/;ta' | sed -e 's/127\.0\.0\.1\${IP_SEPARATOR}//g'), ${myip}" } # Displays virtual info prompt (virtualenv/rvm) From 8e1107730dca1bf88d022782d9eacabbb4651e89 Mon Sep 17 00:00:00 2001 From: Ryan Kanno Date: Fri, 17 Jun 2011 10:31:49 -1000 Subject: [PATCH 17/17] Needed to escape colors correctly for line wrapping to occur. Removed extraneous DEFAULT_COLOR in prompt --- themes/hawaii50/hawaii50.theme.bash | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/themes/hawaii50/hawaii50.theme.bash b/themes/hawaii50/hawaii50.theme.bash index a86821c0..ad87e787 100644 --- a/themes/hawaii50/hawaii50.theme.bash +++ b/themes/hawaii50/hawaii50.theme.bash @@ -31,8 +31,7 @@ # # COLORS ====================================================================== -ORANGE='\e[0;33m' -GREY='\e[1:37m' +ORANGE='\[\e[0;33m\]' DEFAULT_COLOR='\[${white}\]' @@ -48,8 +47,8 @@ RVM_COLOR='\[${cyan}\]' REF_COLOR='\[${purple}\]' # SCM prompts -SCM_THEME_PROMPT_DIRTY=' ${bold_red}✗${normal}' -SCM_THEME_PROMPT_CLEAN=' ${bold_green}✓${normal}' +SCM_THEME_PROMPT_DIRTY=' \[${bold_red}\]✗\[${normal}\]' +SCM_THEME_PROMPT_CLEAN=' \[${bold_green}\]✓\[${normal}\]' SCM_THEME_PROMPT_PREFIX=' on ' SCM_THEME_PROMPT_SUFFIX='' @@ -177,9 +176,9 @@ function prompt() { [ $UID -eq "0" ] && UC=$SUPERUSER_COLOR if [[ $VIRTUAL_PROMPT_ENABLED == 1 ]]; then - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_prompt_info)$(scm_prompt_info) \$ " + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR}) in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(virtual_prompt_info)$(scm_prompt_info) \$ " else - PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR})${DEFAULT_COLOR} in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(scm_prompt_info) \$ " + PS1="$(scm_char) ${UC}\u ${DEFAULT_COLOR}at ${MACHINE_COLOR}\h ${DEFAULT_COLOR}(${IP_COLOR}$(ip)${DEFAULT_COLOR}) in ${DIRECTORY_COLOR}$(limited_pwd)${DEFAULT_COLOR}$(scm_prompt_info) \$ " fi PS2='> ' PS4='+ '