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