Skip to content

Commit

Permalink
Show local status summary symbol (! or ~)
Browse files Browse the repository at this point in the history
Adds a `!` at the end of the local file status indicators if the repo
has unstaged changes, or a `~` if it has uncommitted (staged) changes
but no unstaged changes.

To achieve greater consistency with upstream posh-git, neither this
symbol nor the stash indicator will appear if `bash.enableFileStatus` is
`false`. Further, the rebase indicator has been moved to _before_ the
file status indicators, and is now immediately adjacent to the branch
name/status. This commit does _not_ change the color of the rebase
indicator, which in posh-git is cyan but in posh-git-sh is currently the
default terminal foreground color.

Resolves #40.
  • Loading branch information
rdnlsmith authored and lyze committed Oct 18, 2020
1 parent b1fdea0 commit 9fd10d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
9 changes: 7 additions & 2 deletions README.md
Expand Up @@ -58,7 +58,7 @@ The Prompt
By default, the status summary has the following format:

```sh
[{HEAD-name} x +A ~B -C !D | +E ~F -G !H]
[{HEAD-name} x +A ~B -C !D | +E ~F -G !H W]
```

* `{HEAD-name}` is the current branch, or the SHA of a detached HEAD. The color
Expand All @@ -82,8 +82,13 @@ By default, the status summary has the following format:
* `~` modified
* `-` removed
* `!` conflicting
* `W` represents the overall status of the working directory.
* `!` there are unstaged changes in the working tree
* `~` there are uncommitted changes, i.e. staged changes, in the working tree
waiting to be committed
* None: there are no unstaged or uncommitted changes to the working tree

For example, a status of `[master ≡ +0 ~2 -1 | +1 ~1 -0]` corresponds to the
For example, a status of `[master ≡ +0 ~2 -1 | +1 ~1 -0 !]` corresponds to the
following `git status`:

# On branch master
Expand Down
10 changes: 5 additions & 5 deletions git-prompt-test.sh
Expand Up @@ -203,20 +203,20 @@ run_test_known_diff empty '[master ?]'
one_file_unstaged() {
touch stuff
}
run_test_known_diff one_file_unstaged '[master ? +1 ~0 -0]'
run_test_known_diff one_file_unstaged '[master ? +1 ~0 -0 !]'

one_file_staged() {
touch stuff
git add stuff
}
run_test_known_diff one_file_staged '[master ? +1 ~0 -0]'
run_test_known_diff one_file_staged '[master ? +1 ~0 -0 ~]'

one_file_staged_with_unstaged_edit() {
touch stuff
git add stuff
echo stuff > stuff
}
run_test_known_diff one_file_staged_with_unstaged_edit '[master ? +1 ~0 -0 | +0 ~1 -0]'
run_test_known_diff one_file_staged_with_unstaged_edit '[master ? +1 ~0 -0 | +0 ~1 -0 !]'

one_file_typechange() {
touch file_or_link
Expand All @@ -227,7 +227,7 @@ one_file_typechange() {
rm file_or_link
ln -s target file_or_link
}
run_test_known_diff one_file_typechange '[master ? +0 ~1 -0]'
run_test_known_diff one_file_typechange '[master ? +0 ~1 -0 !]'

one_file_stashed() {
touch stuff
Expand Down Expand Up @@ -266,7 +266,7 @@ added_edited_deleted_staged_and_unstaged() {
# unstaged delete
rm delete_me_2
}
run_test_known_diff added_edited_deleted_staged_and_unstaged '[master ? +1 ~1 -1 | +1 ~1 -1]'
run_test_known_diff added_edited_deleted_staged_and_unstaged '[master ? +1 ~1 -1 | +1 ~1 -1 !]'

# Test summary
if (( $PASSING_WARNING > 0 || $FAILING_WARNING > 0)); then
Expand Down
29 changes: 25 additions & 4 deletions git-prompt.sh
Expand Up @@ -171,6 +171,12 @@ __posh_git_echo () {
local BeforeStash='('
local AfterStash=')'

local LocalDefaultStatusSymbol=''
local LocalWorkingStatusSymbol=' !'
local LocalWorkingStatusColor=$(__posh_color "$Red")
local LocalStagedStatusSymbol=' ~'
local LocalStagedStatusColor=$(__posh_color "$BrightCyan")

local RebaseForegroundColor=$(__posh_color '\e[0m') # reset
local RebaseBackgroundColor=

Expand Down Expand Up @@ -406,10 +412,13 @@ __posh_git_echo () {
gitstring+="$BranchBackgroundColor$BranchForegroundColor$branchstring$BranchIdenticalStatusSymbol"
fi

gitstring+="${rebase:+$RebaseForegroundColor$RebaseBackgroundColor$rebase}"

# index status
if $EnableFileStatus; then
local indexCount="$(( $indexAdded + $indexModified + $indexDeleted + $indexUnmerged ))"
local workingCount="$(( $filesAdded + $filesModified + $filesDeleted + $filesUnmerged ))"

if (( $indexCount != 0 )) || $ShowStatusWhenZero; then
gitstring+="$IndexBackgroundColor$IndexForegroundColor +$indexAdded ~$indexModified -$indexDeleted"
fi
Expand All @@ -425,11 +434,23 @@ __posh_git_echo () {
if (( $filesUnmerged != 0 )); then
gitstring+=" $WorkingBackgroundColor$WorkingForegroundColor!$filesUnmerged"
fi
fi
gitstring+="${rebase:+$RebaseForegroundColor$RebaseBackgroundColor$rebase}"

if $EnableStashStatus && $hasStash; then
gitstring+="$DefaultBackgroundColor$DefaultForegroundColor $StashBackgroundColor$StashForegroundColor$BeforeStash$stashCount$AfterStash"
local localStatusSymbol=$LocalDefaultStatusSymbol
local localStatusColor=$DefaultForegroundColor

if (( workingCount != 0 )); then
localStatusSymbol=$LocalWorkingStatusSymbol
localStatusColor=$LocalWorkingStatusColor
elif (( indexCount != 0 )); then
localStatusSymbol=$LocalStagedStatusSymbol
localStatusColor=$LocalStagedStatusColor
fi

gitstring+="$DefaultBackgroundColor$localStatusColor$localStatusSymbol$DefaultForegroundColor"

if $EnableStashStatus && $hasStash; then
gitstring+="$DefaultBackgroundColor$DefaultForegroundColor $StashBackgroundColor$StashForegroundColor$BeforeStash$stashCount$AfterStash"
fi
fi

# after-branch text
Expand Down

0 comments on commit 9fd10d9

Please sign in to comment.