Skip to content

Commit

Permalink
Add options to disable tracking and local counts
Browse files Browse the repository at this point in the history
By default, the prompt will show counts for both sections. But users can
now easily remove the counts for either or both sections if they want.
  • Loading branch information
telemachus committed Dec 22, 2023
1 parent 55f40bd commit e3b5941
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,24 @@ The `symbol` option prints only `ZSH_THEME_GIT_PROMPT_UPSTREAM_SYMBOL`.
Furthermore, a warning symbol can be configured through `ZSH_THEME_GIT_PROMPT_UPSTREAM_NO_TRACKING` for the case where no remote is available.
`ZSH_THEME_GIT_PROMPT_UPSTREAM_NO_TRACKING` can be set independently of `ZSH_GIT_PROMPT_SHOW_UPSTREAM`.

### Show number of stash entries
The number of stash entries will be shown if `ZSH_GIT_PROMPT_SHOW_STASH` is set.
### Disable display of numbers
By default, the prompt will show counts for each item in the tracking status and local status sections.
(See [Prompt Structure](#prompt-structure) for details about these sections.)
However, you can disable the display of counts for either or both sections of the prompt using `ZSH_GIT_PROMPT_SHOW_TRACKING_COUNTS` and `ZSH_GIT_PROMPT_SHOW_LOCAL_COUNTS`.
If you set these variables to anything other than `1`, then the symbols will show but not the counts.
For example, a prompt such as `[master|✚2]` will become `[master|✚]` instead.

### Show whether there are stash entries
If `ZSH_GIT_PROMPT_SHOW_STASH` is set, the prompt will display a symbol when there are entries in the stash.
Enabling this will execute another Git command every time a new prompt is shown!
To enable stash entries add the following line to your `.zshrc`:

```bash
ZSH_GIT_PROMPT_SHOW_STASH=1
```
By default, the prompt will also show the count of entries in the stash.
The display of a count is controlled by `ZSH_GIT_PROMPT_SHOW_LOCAL_COUNTS`.
See [above][#disable-display-of-counts] for discussion.

### Force blank
Since the prompt is asynchronous by default, the Git status updates slightly delayed.
Expand Down
32 changes: 25 additions & 7 deletions git-prompt.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ autoload -U colors && colors
# Settings
: "${ZSH_GIT_PROMPT_SHOW_UPSTREAM=""}"
: "${ZSH_GIT_PROMPT_SHOW_STASH=""}"
: "${ZSH_GIT_PROMPT_SHOW_TRACKING_COUNTS="1"}"
: "${ZSH_GIT_PROMPT_SHOW_LOCAL_COUNTS="1"}"
: "${ZSH_GIT_PROMPT_ENABLE_SECONDARY=""}"
: "${ZSH_GIT_PROMPT_NO_ASYNC=""}"
: "${ZSH_GIT_PROMPT_FORCE_BLANK=""}"
Expand Down Expand Up @@ -87,6 +89,8 @@ function _zsh_git_prompt_git_status() {
-v DETACHED="$ZSH_THEME_GIT_PROMPT_DETACHED" \
-v BRANCH="$ZSH_THEME_GIT_PROMPT_BRANCH" \
-v UPSTREAM_TYPE="$ZSH_GIT_PROMPT_SHOW_UPSTREAM" \
-v SHOW_TRACKING_COUNTS="$ZSH_GIT_PROMPT_SHOW_TRACKING_COUNTS" \
-v SHOW_LOCAL_COUNTS="$ZSH_GIT_PROMPT_SHOW_LOCAL_COUNTS" \
-v UPSTREAM_SYMBOL="$ZSH_THEME_GIT_PROMPT_UPSTREAM_SYMBOL" \
-v UPSTREAM_NO_TRACKING="$ZSH_THEME_GIT_PROMPT_UPSTREAM_NO_TRACKING" \
-v UPSTREAM_PREFIX="$ZSH_THEME_GIT_PROMPT_UPSTREAM_PREFIX" \
Expand Down Expand Up @@ -193,45 +197,59 @@ function _zsh_git_prompt_git_status() {
if (behind < 0) {
print BEHIND;
printf "%d", behind * -1;
if (SHOW_TRACKING_COUNTS == "1") {
printf "%d", behind * -1;
}
print RC;
}
if (ahead > 0) {
print AHEAD;
printf "%d", ahead;
if (SHOW_TRACKING_COUNTS == "1") {
printf "%d", ahead;
}
print RC;
}
print SEPARATOR;
if (unmerged > 0) {
print UNMERGED;
print unmerged;
if (SHOW_LOCAL_COUNTS == "1") {
print unmerged;
}
print RC;
}
if (staged > 0) {
print STAGED;
print staged;
if (SHOW_LOCAL_COUNTS == "1") {
print staged;
}
print RC;
}
if (unstaged > 0) {
print UNSTAGED;
print unstaged;
if (SHOW_LOCAL_COUNTS == "1") {
print unstaged;
}
print RC;
}
if (untracked > 0) {
print UNTRACKED;
print untracked;
if (SHOW_LOCAL_COUNTS == "1") {
print untracked;
}
print RC;
}
if (stashed > 0) {
print STASHED;
print stashed;
if (SHOW_LOCAL_COUNTS == "1") {
print stashed;
}
print RC;
}
Expand Down

0 comments on commit e3b5941

Please sign in to comment.