From 95ed7da00bd294175af42210cdbed691f4270058 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sat, 9 May 2015 21:33:44 -0300 Subject: [PATCH 1/5] refact(scorphish): show number of commits ahead for all remotes --- themes/scorphish/fish_prompt.fish | 35 ++++++++++++++----------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/themes/scorphish/fish_prompt.fish b/themes/scorphish/fish_prompt.fish index 0c4cb78..9a632c1 100644 --- a/themes/scorphish/fish_prompt.fish +++ b/themes/scorphish/fish_prompt.fish @@ -28,32 +28,29 @@ function _is_git_dirty echo (command git status -s --ignore-submodules=dirty ^/dev/null) end -function _git_ahead_count -a branch_name - echo (command git log origin/$branch_name..HEAD ^/dev/null | \ +function _git_ahead_count -a remote -a branch_name + echo (command git log $remote/$branch_name..HEAD ^/dev/null | \ grep '^commit' | wc -l | tr -d ' ') end -function _git_dirty_remotes -a ahead_color +function _git_dirty_remotes -a remote_color -a ahead_color set current_branch (git rev-parse --abbrev-ref HEAD) set current_ref (git rev-parse HEAD) - set -l git_ahead_count (_git_ahead_count $current_branch) - - if [ $git_ahead_count != 0 ] - set ahead_count "$ahead_color+$git_ahead_count$normal" - end - for remote in (git remote) - # if test $remote != 'origin' - set remote_ref_branch "refs/remotes/$remote/$current_branch" - set remote_ref (git for-each-ref --format='%(objectname)' $remote_ref_branch) - if test "$remote_ref" != '' - if test "$remote_ref" != $current_ref - echo ! - echo "$ahead_count" - end + + set -l git_ahead_count (_git_ahead_count $remote $current_branch) + + set remote_branch "refs/remotes/$remote/$current_branch" + set remote_ref (git for-each-ref --format='%(objectname)' $remote_branch) + if test "$remote_ref" != '' + if test "$remote_ref" != $current_ref + echo -n "$remote_color!" + if [ $git_ahead_count != 0 ] + echo -n "$ahead_color+$git_ahead_count$normal" end - # end + end + end end end @@ -90,7 +87,7 @@ function fish_prompt if [ (_git_branch_name) ] set -l git_branch (_git_branch_name) - set dirty_remotes (_git_dirty_remotes $orange) + set dirty_remotes (_git_dirty_remotes $red $orange) if [ (_is_git_dirty) ] echo -n -s $gray '‹' $yellow $git_branch $red '*' $dirty_remotes $gray '›' $normal From 239f8dd0890b7fc68e27e15bcd582ff3045761c0 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sat, 9 May 2015 21:33:44 -0300 Subject: [PATCH 2/5] refact(scorphish): use a flag to decide where to place git info --- themes/scorphish/fish_prompt.fish | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/themes/scorphish/fish_prompt.fish b/themes/scorphish/fish_prompt.fish index 9a632c1..2df4eae 100644 --- a/themes/scorphish/fish_prompt.fish +++ b/themes/scorphish/fish_prompt.fish @@ -71,7 +71,11 @@ function fish_prompt _prompt_virtualfish set_color -o 666 - echo ']' + if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE + printf "]" + else + printf "]\n" + end set -l gray (set_color 666) set -l cyan (set_color cyan) @@ -97,7 +101,11 @@ function fish_prompt end set_color 060 - printf ' »' + if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE + printf "\n»" + else + printf " »" + end set_color 090 printf '»' set_color 0c0 From afe748e4788c86758a9bfbd61eefcf48362aaadd Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sun, 10 May 2015 01:13:19 -0300 Subject: [PATCH 3/5] refact(scorphish): colorize prompt arrows according to exit code --- themes/scorphish/fish_prompt.fish | 32 +++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/themes/scorphish/fish_prompt.fish b/themes/scorphish/fish_prompt.fish index 2df4eae..05c3adf 100644 --- a/themes/scorphish/fish_prompt.fish +++ b/themes/scorphish/fish_prompt.fish @@ -55,6 +55,8 @@ function _git_dirty_remotes -a remote_color -a ahead_color end function fish_prompt + set -l exit_code $status + set_color -o 666 printf '[' set_color -o blue @@ -72,9 +74,9 @@ function fish_prompt set_color -o 666 if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE - printf "]" + printf ']' else - printf "]\n" + printf ']\n' end set -l gray (set_color 666) @@ -100,18 +102,24 @@ function fish_prompt end end - set_color 060 - if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE - printf "\n»" + if test $exit_code -ne 0 + set arrow_colors 600 900 c00 f00 else - printf " »" + set arrow_colors 060 090 0c0 0f0 end - set_color 090 - printf '»' - set_color 0c0 - printf '»' - set_color 0f0 - printf '» ' + + if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE + printf '\n' + else + printf ' ' + end + + for arrow_color in $arrow_colors + set_color $arrow_color + printf '»' + end + + printf ' ' set_color normal end From 3ee86741124d2bc1fdfc211315aa736de127229b Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sun, 10 May 2015 23:51:25 -0300 Subject: [PATCH 4/5] refact(scorphish): display nada when there's neither venv nor ruby --- themes/scorphish/fish_prompt.fish | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/themes/scorphish/fish_prompt.fish b/themes/scorphish/fish_prompt.fish index 05c3adf..7d98a25 100644 --- a/themes/scorphish/fish_prompt.fish +++ b/themes/scorphish/fish_prompt.fish @@ -1,6 +1,6 @@ # name: scorphish -function _prompt_rubies -d 'Display current Ruby (rvm/rbenv)' +function _prompt_rubies -a sep_color -a ruby_color -d 'Display current Ruby (rvm/rbenv)' [ "$theme_display_ruby" = 'no' ]; and return set -l ruby_version if type rvm-prompt >/dev/null 2>&1 @@ -8,16 +8,16 @@ function _prompt_rubies -d 'Display current Ruby (rvm/rbenv)' else if type rbenv >/dev/null 2>&1 set ruby_version (rbenv version-name) # Don't show global ruby version... - [ "$ruby_version" = (rbenv global) ]; and echo -n -s '--'; and return + [ "$ruby_version" = (rbenv global) ]; and return end [ -z "$ruby_version" ]; and return - echo -n -s $ruby_version + echo -n -s $sep_color '|' $ruby_color $ruby_version end -function _prompt_virtualfish -d "Display activated virtual environment (only for virtualfish, virtualenv's activate.fish changes prompt by itself)" - [ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]; and echo -n -s '--'; and return - echo -n -s (basename "$VIRTUAL_ENV") +function _prompt_virtualfish -a sep_color -a venv_color -d "Display activated virtual environment (only for virtualfish, virtualenv's activate.fish changes prompt by itself)" + [ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]; and return + echo -n -s $sep_color '|' $venv_color (basename "$VIRTUAL_ENV") end function _git_branch_name @@ -62,15 +62,9 @@ function fish_prompt set_color -o blue printf '%s' (prompt_pwd) - set_color -o 666 - printf '|' - set_color -o red - _prompt_rubies + _prompt_rubies (set_color -o 666) (set_color -o red) - set_color -o 666 - printf '|' - set_color -o green - _prompt_virtualfish + _prompt_virtualfish (set_color -o 666) (set_color -o green) set_color -o 666 if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE From e5ef2da81f0578d4f835acdbe44caef363f57cf7 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sun, 10 May 2015 23:56:52 -0300 Subject: [PATCH 5/5] refact(scorphish): set colors on top of method to use them onwards --- themes/scorphish/fish_prompt.fish | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/themes/scorphish/fish_prompt.fish b/themes/scorphish/fish_prompt.fish index 7d98a25..3f8b166 100644 --- a/themes/scorphish/fish_prompt.fish +++ b/themes/scorphish/fish_prompt.fish @@ -57,14 +57,24 @@ end function fish_prompt set -l exit_code $status + set -l gray (set_color 666) + set -l cyan (set_color cyan) + set -l red (set_color red) + set -l normal (set_color normal) + set -l yellow (set_color ffcc00) + set -l orange (set_color ffb300) + set -l green (set_color green) + set -l pink (set_color ff99ff) + set -l dark_pink (set_color cc99ff) + set_color -o 666 printf '[' set_color -o blue printf '%s' (prompt_pwd) - _prompt_rubies (set_color -o 666) (set_color -o red) + _prompt_rubies $gray $red - _prompt_virtualfish (set_color -o 666) (set_color -o green) + _prompt_virtualfish $gray $green set_color -o 666 if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE @@ -73,16 +83,6 @@ function fish_prompt printf ']\n' end - set -l gray (set_color 666) - set -l cyan (set_color cyan) - set -l red (set_color red) - set -l normal (set_color normal) - set -l yellow (set_color ffcc00) - set -l orange (set_color ffb300) - set -l green (set_color 80ff00) - set -l pink (set_color ff99ff) - set -l dark_pink (set_color cc99ff) - # Show git branch and dirty state if [ (_git_branch_name) ] set -l git_branch (_git_branch_name)