Mercurial > hg > mercurial-crew-with-dirclash
annotate contrib/bash_completion @ 1121:14a69c4988cd
NoOptionError is unknown there.
author | Ollivier Robert <roberto@keltia.freenix.fr> |
---|---|
date | Sat, 27 Aug 2005 23:43:13 -0700 |
parents | 89f54e72581d |
children | f82b084bd904 |
rev | line source |
---|---|
1115
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
1 #!/bin/bash |
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
2 |
916 | 3 _hg_commands() |
4 { | |
5 local commands="$(hg -v help | sed -e '1,/^list of commands:/d' \ | |
952
dbfabfcb485e
bash_completion: support GNU sed 3 and non-GNU sed
TK Soh <teekaysoh@yahoo.com>
parents:
935
diff
changeset
|
6 -e '/^global options:/,$d' \ |
916 | 7 -e '/^ [^ ]/!d; s/[,:]//g;')" |
8 | |
9 # hide debug commands from users, but complete them if | |
10 # specifically asked for | |
11 if [[ "$cur" == de* ]]; then | |
12 commands="$commands debugcheckstate debugstate debugindex" | |
1115
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
13 commands="$commands debugindexdot debugwalk debugdata" |
916 | 14 fi |
15 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$commands" -- "$cur") ) | |
16 } | |
17 | |
18 _hg_paths() | |
19 { | |
20 local paths="$(hg paths | sed -e 's/ = .*$//')" | |
21 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" )) | |
22 } | |
23 | |
935
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
24 _hg_status() |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
25 { |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
26 local files="$( hg status -$1 | cut -b 3- )" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
27 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$files" -- "$cur" )) |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
28 } |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
29 |
916 | 30 _hg_tags() |
31 { | |
32 local tags="$(hg tags | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')" | |
33 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$tags" -- "$cur") ) | |
34 } | |
35 | |
36 # this is "kind of" ugly... | |
37 _hg_count_non_option() | |
38 { | |
39 local i count=0 | |
40 local filters="$1" | |
41 | |
42 for (( i=1; $i<=$COMP_CWORD; i++ )); do | |
43 if [[ "${COMP_WORDS[i]}" != -* ]]; then | |
44 for f in $filters; do | |
45 if [[ ${COMP_WORDS[i-1]} == $f ]]; then | |
46 continue 2 | |
47 fi | |
48 done | |
49 count=$(($count + 1)) | |
50 fi | |
51 done | |
52 | |
53 echo $(($count - 1)) | |
54 } | |
55 | |
56 _hg() | |
57 { | |
58 local cur prev cmd opts i | |
59 | |
60 COMPREPLY=() | |
61 cur="$2" | |
62 prev="$3" | |
63 | |
64 # searching for the command | |
65 # (first non-option argument that doesn't follow -R/--repository) | |
66 for (( i=1; $i<=$COMP_CWORD; i++ )); do | |
67 if [[ ${COMP_WORDS[i]} != -* ]] \ | |
68 && [ "${COMP_WORDS[i-1]}" != -R ] \ | |
69 && [ "${COMP_WORDS[i-1]}" != --repository ]; then | |
70 cmd="${COMP_WORDS[i]}" | |
71 break | |
72 fi | |
73 done | |
74 | |
75 if [[ "$cur" == -* ]]; then | |
76 opts="$(hg -v help | sed -e '1,/^global options/d; /^ -/!d')" | |
77 | |
78 if [ -n "$cmd" ]; then | |
79 opts="$opts $(hg help "$cmd" | sed -e '/^ -/!d; s/ [^-][^ ]*//')" | |
80 fi | |
81 | |
82 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") ) | |
83 return | |
84 fi | |
85 | |
86 if [ "$prev" = -R ] || [ "$prev" = --repository ]; then | |
87 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
88 return | |
89 fi | |
90 | |
91 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then | |
92 _hg_commands | |
93 return | |
94 fi | |
95 | |
96 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then | |
97 _hg_tags | |
98 return | |
99 fi | |
100 | |
101 case "$cmd" in | |
102 help) | |
103 _hg_commands | |
104 ;; | |
105 export|manifest|update|checkout|up|co) | |
106 _hg_tags | |
107 ;; | |
1018 | 108 pull|push|outgoing|incoming|out|in) |
916 | 109 _hg_paths |
110 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
111 ;; | |
112 paths) | |
113 _hg_paths | |
114 ;; | |
935
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
115 add) |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
116 _hg_status "u" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
117 ;; |
1018 | 118 commit|ci) |
935
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
119 _hg_status "mra" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
120 ;; |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
121 remove) |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
122 _hg_status "r" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
123 ;; |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
124 forget) |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
125 _hg_status "a" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
126 ;; |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
127 diff) |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
128 _hg_status "mra" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
129 ;; |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
130 revert) |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
131 _hg_status "mra" |
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
132 ;; |
916 | 133 clone) |
134 local count=$(_hg_count_non_option) | |
135 if [ $count = 1 ]; then | |
136 _hg_paths | |
137 fi | |
138 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" )) | |
139 ;; | |
1115
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
140 debugindex|debugindexdot) |
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
141 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" )) |
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
142 ;; |
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
143 debugdata) |
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
144 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.d" -- "$cur" )) |
89f54e72581d
bash_completion: add debugindex and debugdata support
mpm@selenic.com
parents:
1018
diff
changeset
|
145 ;; |
916 | 146 cat) |
147 local count=$(_hg_count_non_option -o --output) | |
148 if [ $count = 2 ]; then | |
149 _hg_tags | |
150 else | |
151 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) | |
152 fi | |
153 ;; | |
154 *) | |
155 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" )) | |
156 ;; | |
157 esac | |
158 | |
159 } | |
160 | |
935
925563ff1b18
bash: Add smarter completion of add/commit/remove/forget/diff/revert
mpm@selenic.com
parents:
929
diff
changeset
|
161 complete -o default -F _hg hg |