]> arthur.barton.de Git - ax-zsh.git/blobdiff - plugins/git/git.zshrc
git: Return prompt fragments only inside of a Git repository
[ax-zsh.git] / plugins / git / git.zshrc
index fae59ff294480a544d701a5871455d46a9ae488e..2b039c2a4e24ada3e68645182ffe7583b4f50706 100644 (file)
@@ -36,17 +36,32 @@ git_prompt_behind() {
                && echo "$ZSH_THEME_VCS_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() {
-       ref=$(git symbolic-ref HEAD 2>/dev/null) || return 1
-       echo "${ref#refs/heads/}$(git_parse_dirty)$(git_prompt_ahead)$(git_prompt_behind)"
+       local prompt=$(git_prompt_info)
+       [[ -n "$prompt" ]] || return 1
+       echo "$prompt$(git_prompt_status)"
        return 0
 }
 
+# OhMyZsh compatibility functions
+alias parse_git_dirty=git_parse_dirty
+
 ax_vcs_prompt_functions=($ax_vcs_prompt_functions git_prompt)
 
 alias ga="git add"
 alias gc="git commit"
-alias gd="git diff"
-alias gdc="git diff --cached"
+alias gd="git diff --patch-with-stat"
+alias gdc="git diff --patch-with-stat --cached"
 alias gst="git status --short --branch --untracked"
 alias fix="git diff --name-only | uniq | xargs $EDITOR"