]> arthur.barton.de Git - ax-zsh.git/commitdiff
git: Return prompt fragments only inside of a Git repository
authorAlexander Barton <alex@barton.de>
Tue, 5 Feb 2019 21:32:38 +0000 (22:32 +0100)
committerAlexander Barton <alex@barton.de>
Tue, 5 Feb 2019 21:32:40 +0000 (22:32 +0100)
plugins/git/git.zshrc

index 55c395f6b887caa0c74ae2e77c5681a334c4f028..2b039c2a4e24ada3e68645182ffe7583b4f50706 100644 (file)
@@ -38,15 +38,18 @@ git_prompt_behind() {
 
 git_prompt_info() {
        local ref=$(git symbolic-ref HEAD 2>/dev/null) || return 1
+       [[ -n "$ref" ]] || return 1
        echo "${ref#refs/heads/}"
 }
 git_prompt_status() {
+       local ref=$(git symbolic-ref HEAD 2>/dev/null) || return 1
+       [[ -n "$ref" ]] || return 1
        echo "$(git_parse_dirty)$(git_prompt_ahead)$(git_prompt_behind)"
 }
 
 git_prompt() {
        local prompt=$(git_prompt_info)
-       [[ -n "$prompt" ]] || return 0
+       [[ -n "$prompt" ]] || return 1
        echo "$prompt$(git_prompt_status)"
        return 0
 }