From 8a0d794337046f023474ff47b33e34b814bfeeb8 Mon Sep 17 00:00:00 2001 From: hyperfekt Date: Tue, 12 Mar 2019 09:01:05 +0100 Subject: [PATCH] fish_git_prompt: optionally show stash state in informative mode --- CHANGELOG.md | 1 + share/functions/fish_git_prompt.fish | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d10fabb4..0099e2300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - `cf` - `bosh` - `vagrant` +- The git prompt in informative mode now shows the number of stashes if enabled. ### For distributors and developers - The autotools-based build system and legacy Xcode build systems have been removed, leaving only the CMake build system. All distributors and developers must migrate to the CMake build. diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index cb96b31eb..6f9657d1f 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -102,6 +102,7 @@ # invalidstate (✖) # stagedstate (●) # untrackedfiles (…) +# stashstate (⚑) # cleanstate (✔) # # @@ -401,7 +402,7 @@ function fish_git_prompt --description "Prompt function for Git" and test "$dirty" != false and test "$untracked" != false end - set informative_status "$space"(__fish_git_prompt_informative_status) + set informative_status "$space"(__fish_git_prompt_informative_status $git_dir) else # This has to be set explicitly. if test "$dirty" = true @@ -517,6 +518,9 @@ function __fish_git_prompt_dirty --description "fish_git_prompt helper, tells wh end set -g ___fish_git_prompt_status_order stagedstate invalidstate dirtystate untrackedfiles +if set -q __fish_git_prompt_showstashstate + set -a ___fish_git_prompt_status_order stashstate +end function __fish_git_prompt_informative_status @@ -530,11 +534,16 @@ function __fish_git_prompt_informative_status set -l invalidstate (count (string match -r "U" -- $stagedFiles)) set -l stagedstate (math $x - $invalidstate) set -l untrackedfiles (command git ls-files --others --exclude-standard | wc -l | string trim) + set -l stashstate 0 + set -l stashfile "$argv[1]/logs/refs/stash" + if set -q __fish_git_prompt_showstashstate; and test -e "$stashfile" + set stashstate (wc -l $stashfile | string match -r '\d+') + end set -l info # If `math` fails for some reason, assume the state is clean - it's the simpler path - set -l state (math $dirtystate + $invalidstate + $stagedstate + $untrackedfiles 2>/dev/null) + set -l state (math $dirtystate + $invalidstate + $stagedstate + $untrackedfiles + $stashstate 2>/dev/null) if test -z "$state" or test "$state" = 0 set info $___fish_git_prompt_color_cleanstate$___fish_git_prompt_char_cleanstate$___fish_git_prompt_color_cleanstate_done @@ -686,7 +695,7 @@ function __fish_git_prompt_validate_chars --description "fish_git_prompt helper, __fish_git_prompt_set_char __fish_git_prompt_char_dirtystate '*' '✚' __fish_git_prompt_set_char __fish_git_prompt_char_invalidstate '#' '✖' __fish_git_prompt_set_char __fish_git_prompt_char_stagedstate '+' '●' - __fish_git_prompt_set_char __fish_git_prompt_char_stashstate '$' + __fish_git_prompt_set_char __fish_git_prompt_char_stashstate '$' '⚑' __fish_git_prompt_set_char __fish_git_prompt_char_stateseparator ' ' '|' __fish_git_prompt_set_char __fish_git_prompt_char_untrackedfiles '%' '…' __fish_git_prompt_set_char __fish_git_prompt_char_upstream_ahead '>' '↑' @@ -778,7 +787,7 @@ function __fish_git_prompt_repaint $varargs --description "Event handler, repain if status --is-interactive if test $argv[3] = __fish_git_prompt_show_informative_status # Clear characters that have different defaults with/without informative status - for name in cleanstate dirtystate invalidstate stagedstate stateseparator untrackedfiles upstream_ahead upstream_behind + for name in cleanstate dirtystate invalidstate stagedstate stashstate stateseparator untrackedfiles upstream_ahead upstream_behind set -e ___fish_git_prompt_char_$name end end