]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/mercurial/mercurial.plugin.zsh
...
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / mercurial / mercurial.plugin.zsh
1 # aliases
2 alias hga='hg add'
3 alias hgc='hg commit'
4 alias hgca='hg commit --amend'
5 alias hgci='hg commit --interactive'
6 alias hgb='hg branch'
7 alias hgba='hg branches'
8 alias hgbk='hg bookmarks'
9 alias hgco='hg checkout'
10 alias hgd='hg diff'
11 alias hged='hg diffmerge'
12 alias hgp='hg push'
13 alias hgs='hg status'
14 alias hgsl='hg log --limit 20 --template "{node|short} | {date|isodatesec} | {author|person}: {desc|strip|firstline}\n" '
15 alias hgun='hg resolve --list'
16 # pull and update
17 alias hgi='hg incoming'
18 alias hgl='hg pull -u'
19 alias hglr='hg pull --rebase'
20 alias hgo='hg outgoing'
21 alias hglg='hg log --stat -v'
22 alias hglgp='hg log --stat  -p -v'
23
24 function hgic() {
25   hg incoming "$@" | grep "changeset" | wc -l
26 }
27
28 function hgoc() {
29   hg outgoing "$@" | grep "changeset" | wc -l
30 }
31
32 # functions
33 function hg_root() {
34   local dir="$PWD"
35   while [[ "$dir" != "/" ]]; do
36     if [[ -d "$dir/.hg" ]]; then
37       echo "$dir"
38       return 0
39     fi
40     dir="${dir:h}"
41   done
42   return 1
43 }
44
45 function in_hg() {
46   hg_root >/dev/null
47 }
48
49 function hg_get_branch_name() {
50   local dir
51   if ! dir=$(hg_root); then
52     return
53   fi
54
55   if [[ ! -f "$dir/.hg/branch" ]]; then
56     echo default
57     return
58   fi
59
60   echo "$(<"$dir/.hg/branch")"
61 }
62
63 function hg_get_bookmark_name() {
64   local dir
65   if ! dir=$(hg_root); then
66     return
67   fi
68
69   if [[ ! -f "$dir/.hg/bookmarks.current" ]]; then
70     return
71   fi
72
73   echo "$(<"$dir/.hg/bookmarks.current")"
74 }
75
76 function hg_prompt_info {
77   local dir branch dirty
78   if ! dir=$(hg_root); then
79     return
80   fi
81
82   if [[ ! -f "$dir/.hg/branch" ]]; then
83     branch=default
84   else
85     branch="$(<"$dir/.hg/branch")"
86   fi
87
88   dirty="$(hg_dirty)"
89
90   echo "${ZSH_THEME_HG_PROMPT_PREFIX}${branch:gs/%/%%}${dirty}${ZSH_THEME_HG_PROMPT_SUFFIX}"
91 }
92
93 function hg_dirty {
94   # Do nothing if clean / dirty settings aren't defined
95   if [[ -z "$ZSH_THEME_HG_PROMPT_DIRTY" && -z "$ZSH_THEME_HG_PROMPT_CLEAN" ]]; then
96     return
97   fi
98
99   # Check if there are modifications
100   local hg_status
101   if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" = true ]]; then
102     if ! hg_status="$(hg status -q 2>/dev/null)"; then
103       return
104     fi
105   else
106     if ! hg_status="$(hg status 2>/dev/null)"; then
107       return
108     fi
109   fi
110
111   # grep exits with 0 when dirty
112   if command grep -Eq '^\s*[ACDIMR!?L].*$' <<< "$hg_status"; then
113     echo $ZSH_THEME_HG_PROMPT_DIRTY
114     return
115   fi
116
117   echo $ZSH_THEME_HG_PROMPT_CLEAN
118 }