]> arthur.barton.de Git - ax-zsh.git/blob - plugins/git/git.zshrc
git: Bring aliases in line with OhMyZsh (and extend our list!)
[ax-zsh.git] / plugins / git / git.zshrc
1 # AX-ZSH: Alex' Modular ZSH Configuration
2 # git.zshrc: Setup Git
3
4 # Make sure that "git(1)" is installed
5 (( $+commands[git] )) || return
6
7 git_parse_dirty() {
8         local flags
9         flags=(
10                 '--porcelain'
11                 '--ignore-submodules=dirty'
12                 #'--untracked-files=no'
13         )
14         [[ -n "$(git status $flags 2>/dev/null | tail -n1)" ]] \
15                 && echo "$ZSH_THEME_VCS_PROMPT_DIRTY" \
16                 || echo "$ZSH_THEME_VCS_PROMPT_CLEAN"
17 }
18
19 git_current_branch() {
20         local ref=$(git symbolic-ref --quiet HEAD 2>/dev/null)
21         local ret=$?
22         if [[ $ret != 0 ]]; then
23                 [[ $ret == 128 ]] && return             # No Git repository
24                 ref=$(git rev-parse --short HEAD 2>/dev/null) || return
25         fi
26         echo "${ref#refs/heads/}"
27 }
28
29 git_prompt_ahead() {
30         [[ -n "$(git rev-list "@{upstream}..HEAD" 2>/dev/null)" ]] \
31                 && echo "$ZSH_THEME_VCS_PROMPT_AHEAD"
32 }
33
34 git_prompt_behind() {
35         [[ -n "$(git rev-list HEAD..@{upstream} 2>/dev/null)" ]] \
36                 && echo "$ZSH_THEME_VCS_PROMPT_BEHIND"
37 }
38
39 git_prompt_info() {
40         local ref=$(git symbolic-ref HEAD 2>/dev/null) || return 1
41         [[ -n "$ref" ]] || return 1
42         echo "${ZSH_THEME_VCS_PROMPT_PREFIX}${ref#refs/heads/}${ZSH_THEME_VCS_PROMPT_SUFFIX}"
43 }
44 git_prompt_status() {
45         local ref=$(git symbolic-ref HEAD 2>/dev/null) || return 1
46         [[ -n "$ref" ]] || return 1
47         echo "$(git_parse_dirty)$(git_prompt_ahead)$(git_prompt_behind)"
48 }
49
50 git_prompt() {
51         local prompt=$(git_prompt_info)
52         [[ -n "$prompt" ]] || return 1
53         echo "$prompt$(git_prompt_status)"
54         return 0
55 }
56
57 # OhMyZsh compatibility functions
58 alias parse_git_dirty=git_parse_dirty
59
60 ax_vcs_prompt_functions=($ax_vcs_prompt_functions git_prompt)
61
62 alias fix="gd --name-only | uniq | xargs $EDITOR"
63 alias g="git"
64 alias ga="g add"
65 alias gapa="ga --patch"
66 alias gc="g commit --verbose"
67 alias gd="g diff"
68 alias gdca="gd --cached"
69 alias gdcw="gdca --word-diff"
70 alias gdw="gd --word-diff"
71 alias gf="g fetch"
72 alias gfa="gf --all --prune"
73 alias gl="g pull"
74 alias gp="g push"
75 alias gsb="gss --branch"
76 alias gsh="g show"
77 alias gss="gst --short"
78 alias gst="g status"