From ca9910edb740c263548b851faf16c47389f7747e Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 4 Apr 2021 16:44:01 +0200 Subject: [PATCH] fish_git_prompt: Add colors for dirty/staged branches This is a neat feature of the terlar git prompt --- doc_src/cmds/fish_git_prompt.rst | 4 +++- share/functions/fish_git_prompt.fish | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc_src/cmds/fish_git_prompt.rst b/doc_src/cmds/fish_git_prompt.rst index 3648ce8d3..3180e52f7 100644 --- a/doc_src/cmds/fish_git_prompt.rst +++ b/doc_src/cmds/fish_git_prompt.rst @@ -115,8 +115,10 @@ Variables used with ``showupstream`` (also implied by informative status): Colors used with ``showcolorhints``: -- ``$__fish_git_prompt_color_branch`` (green) - the color of the branch +- ``$__fish_git_prompt_color_branch`` (green) - the color of the branch if nothing else applies - ``$__fish_git_prompt_color_branch_detached`` (red) the color of the branch if it's detached (e.g. a commit is checked out) +- ``$__fish_git_prompt_color_branch_dirty`` (no default) the color of the branch if it's dirty and not detached +- ``$__fish_git_prompt_color_branch_staged`` (no default) the color of the branch if it just has something staged and is otherwise clean - ``$__fish_git_prompt_color_flags`` (--bold blue) - the default color for dirty/staged/stashed/untracked state Note that all colors can also have a corresponding ``_done`` color. For example, the contents of ``$__fish_git_prompt_color_upstream_done`` is printed right _after_ the upstream. diff --git a/share/functions/fish_git_prompt.fish b/share/functions/fish_git_prompt.fish index 06477800d..459449119 100644 --- a/share/functions/fish_git_prompt.fish +++ b/share/functions/fish_git_prompt.fish @@ -299,6 +299,12 @@ function fish_git_prompt --description "Prompt function for Git" if test $detached = yes set branch_color $___fish_git_prompt_color_branch_detached set branch_done $___fish_git_prompt_color_branch_detached_done + else if test -n "$dirtystate$untrackedfiles"; and set -q __fish_git_prompt_color_branch_dirty + set branch_color (set_color $__fish_git_prompt_color_branch_dirty) + set branch_done (set_color $__fish_git_prompt_color_branch_dirty_done) + else if test -n "$stagedstate"; and set -q __fish_git_prompt_color_branch_staged + set branch_color (set_color $__fish_git_prompt_color_branch_staged) + set branch_done (set_color $__fish_git_prompt_color_branch_staged_done) end end