Skip to content

Commit

Permalink
Configure status symbol visibility (lyze#19)
Browse files Browse the repository at this point in the history
Toggle status symbol with bash.enableStatusSymbol.
  • Loading branch information
dewe authored and lyze committed Dec 10, 2016
1 parent c903f4b commit 4cf1067
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -26,7 +26,7 @@ Installation Instructions
will show username, at-sign, host, colon, cwd, then various status strings,
followed by dollar and space, as your prompt. This invocation prepends this
instruction to the existing value of `PROMPT_COMMAND`.

If you are using `zsh`, you need to set the
[`PROMPT`](http://zsh.sourceforge.net/Doc/Release/Parameters.html#index-PROMPT)
variable or the
Expand Down Expand Up @@ -176,6 +176,13 @@ legacy | Does not use the `--count` option available in recent versions of `git-
git | _Default_. Always compares `HEAD` to `@{upstream}`
svn | Always compares `HEAD` to `SVN` upstream

### bash.enableStatusSymbol

Option | Description
------ | -----------
true | _Default_. Status symbols (`` `` `` ``) will be shown.
false | No status symbol will be shown, saving some prompt length.


Background
----------
Expand Down
39 changes: 30 additions & 9 deletions git-prompt.sh
Expand Up @@ -90,6 +90,15 @@
# `git-rev-list`
# git | _Default_. Always compares `HEAD` to `@{upstream}`
# svn | Always compares `HEAD` to `SVN` upstream
#
# bash.enableStatusSymbol
# -----------------------

# Option | Description
# ------ | -----------
# true | _Default_. Status symbols (`≡` `↑` `↓` `↕`) will be shown.
# false | No status symbol will be shown, saving some prompt length.
#
###############################################################################

# Convenience function to set PS1 to show git status. Must supply two
Expand Down Expand Up @@ -145,11 +154,6 @@ __posh_git_echo () {
local AfterForegroundColor=$(__posh_color '\e[1;33m') # Yellow
local AfterBackgroundColor=

local BranchIdenticalStatusToSymbol=$'\xE2\x89\xA1' # Three horizontal lines
local BranchAheadStatusSymbol=$'\xE2\x86\x91' # Up Arrow
local BranchBehindStatusSymbol=$'\xE2\x86\x93' # Down Arrow
local BranchBehindAndAheadStatusSymbol=$'\xE2\x86\x95' # Up and Down Arrow

local BranchForegroundColor=$(__posh_color '\e[1;36m') # Cyan
local BranchBackgroundColor=
local BranchAheadForegroundColor=$(__posh_color '\e[1;32m') # Green
Expand Down Expand Up @@ -194,6 +198,23 @@ __posh_git_echo () {
false) ShowStashState=false ;;
*) ShowStashState=true ;;
esac
local EnableStatusSymbol=`git config --bool bash.enableStatusSymbol`
case "$EnableStatusSymbol" in
true) EnableStatusSymbol=true ;;
false) EnableStatusSymbol=false ;;
*) EnableStatusSymbol=true ;;
esac

local BranchIdenticalStatusSymbol=''
local BranchAheadStatusSymbol=''
local BranchBehindStatusSymbol=''
local BranchBehindAndAheadStatusSymbol=''
if $EnableStatusSymbol; then
BranchIdenticalStatusSymbol=$' \xE2\x89\xA1' # Three horizontal lines
BranchAheadStatusSymbol=$' \xE2\x86\x91' # Up Arrow
BranchBehindStatusSymbol=$' \xE2\x86\x93' # Down Arrow
BranchBehindAndAheadStatusSymbol=$' \xE2\x86\x95' # Up and Down Arrow
fi

# these globals are updated by __posh_git_ps1_upstream_divergence
__POSH_BRANCH_AHEAD_BY=0
Expand Down Expand Up @@ -343,13 +364,13 @@ __posh_git_echo () {

# branch
if (( $__POSH_BRANCH_BEHIND_BY > 0 && $__POSH_BRANCH_AHEAD_BY > 0 )); then
gitstring+="$BranchBehindAndAheadBackgroundColor$BranchBehindAndAheadForegroundColor$branchstring $BranchBehindAndAheadStatusSymbol"
gitstring+="$BranchBehindAndAheadBackgroundColor$BranchBehindAndAheadForegroundColor$branchstring$BranchBehindAndAheadStatusSymbol"
elif (( $__POSH_BRANCH_BEHIND_BY > 0 )); then
gitstring+="$BranchBehindBackgroundColor$BranchBehindForegroundColor$branchstring $BranchBehindStatusSymbol"
gitstring+="$BranchBehindBackgroundColor$BranchBehindForegroundColor$branchstring$BranchBehindStatusSymbol"
elif (( $__POSH_BRANCH_AHEAD_BY > 0 )); then
gitstring+="$BranchAheadBackgroundColor$BranchAheadForegroundColor$branchstring $BranchAheadStatusSymbol"
gitstring+="$BranchAheadBackgroundColor$BranchAheadForegroundColor$branchstring$BranchAheadStatusSymbol"
else
gitstring+="$BranchBackgroundColor$BranchForegroundColor$branchstring $BranchIdenticalStatusToSymbol"
gitstring+="$BranchBackgroundColor$BranchForegroundColor$branchstring$BranchIdenticalStatusSymbol"
fi

# index status
Expand Down

0 comments on commit 4cf1067

Please sign in to comment.