Skip to content

Commit

Permalink
feat: replace extra command with --show-stash
Browse files Browse the repository at this point in the history
Since git 2.35 `git status` supports a `--show-status` flag. We can use
this instead of a second call to `git`.
  • Loading branch information
telemachus committed Dec 23, 2023
1 parent c8bd857 commit 4c16512
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions git-prompt.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# Configuration
: ${ZSH_GIT_PROMPT_SHOW_UPSTREAM_NAME=""}
: ${ZSH_GIT_PROMPT_SHOW_UPSTREAM_MISSING="1"}
: ${ZSH_GIT_PROMPT_SHOW_STASH=""}
: ${ZSH_GIT_PROMPT_NO_ASYNC=""}
: ${ZSH_GIT_PROMPT_AWK_CMD=""}

Expand Down Expand Up @@ -61,12 +60,8 @@ setopt PROMPT_SUBST
function _zsh_git_prompt_git_status() {
emulate -L zsh
{
[[ -n "$ZSH_GIT_PROMPT_SHOW_STASH" ]] && (
c=$(command git rev-list --walk-reflogs --count refs/stash 2> /dev/null)
[[ -n "$c" ]] && echo "# stash.count $c"
)
GIT_OPTIONAL_LOCKS=0 command git status --branch --porcelain=v2 2>&1 \
|| echo "fatal: git command failed"
GIT_OPTIONAL_LOCKS=0 command git status --branch --porcelain=v2 \
--show-stash 2>&1 || echo "fatal: git command failed"
} | $ZSH_GIT_PROMPT_AWK_CMD \
-v SHOW_UPSTREAM_NAME="$ZSH_GIT_PROMPT_SHOW_UPSTREAM_NAME" \
-v SHOW_UPSTREAM_MISSING="$ZSH_GIT_PROMPT_SHOW_UPSTREAM_MISSING" \
Expand Down Expand Up @@ -139,7 +134,7 @@ function _zsh_git_prompt_git_status() {
}
}
$2 == "stash.count" {
$2 == "stash" {
stashed = $3;
}
Expand Down

0 comments on commit 4c16512

Please sign in to comment.