##// END OF EJS Templates
Added new debug commands to bash_completion.
Thomas Arendsen Hein -
r1263:bc1815cf default
parent child Browse files
Show More
@@ -1,170 +1,171 b''
1 1 #!/bin/bash
2 2
3 3 _hg_commands()
4 4 {
5 5 local commands="$(hg -v help | sed -e '1,/^list of commands:/d' \
6 6 -e '/^global options:/,$d' \
7 7 -e '/^ [^ ]/!d; s/[,:]//g;')"
8 8
9 9 # hide debug commands from users, but complete them if
10 10 # specifically asked for
11 11 if [[ "$cur" == de* ]]; then
12 12 commands="$commands debugcheckstate debugstate debugindex"
13 13 commands="$commands debugindexdot debugwalk debugdata"
14 commands="$commands debugancestor debugconfig debugrename"
14 15 fi
15 16 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$commands" -- "$cur") )
16 17 }
17 18
18 19 _hg_paths()
19 20 {
20 21 local paths="$(hg paths | sed -e 's/ = .*$//')"
21 22 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$paths" -- "$cur" ))
22 23 }
23 24
24 25 _hg_status()
25 26 {
26 27 local files="$( hg status -$1 | cut -b 3- )"
27 28 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -W "$files" -- "$cur" ))
28 29 }
29 30
30 31 _hg_tags()
31 32 {
32 33 local tags="$(hg tags | sed -e 's/[0-9]*:[a-f0-9]\{40\}$//; s/ *$//')"
33 34 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$tags" -- "$cur") )
34 35 }
35 36
36 37 # this is "kind of" ugly...
37 38 _hg_count_non_option()
38 39 {
39 40 local i count=0
40 41 local filters="$1"
41 42
42 43 for (( i=1; $i<=$COMP_CWORD; i++ )); do
43 44 if [[ "${COMP_WORDS[i]}" != -* ]]; then
44 45 if [[ ${COMP_WORDS[i-1]} == @($filters|$global_args) ]]; then
45 46 continue
46 47 fi
47 48 count=$(($count + 1))
48 49 fi
49 50 done
50 51
51 52 echo $(($count - 1))
52 53 }
53 54
54 55 _hg()
55 56 {
56 57 local cur prev cmd opts i
57 58 # global options that receive an argument
58 59 local global_args='--cwd|-R|--repository'
59 60
60 61 COMPREPLY=()
61 62 cur="$2"
62 63 prev="$3"
63 64
64 65 # searching for the command
65 66 # (first non-option argument that doesn't follow a global option that
66 67 # receives an argument)
67 68 for (( i=1; $i<=$COMP_CWORD; i++ )); do
68 69 if [[ ${COMP_WORDS[i]} != -* ]]; then
69 70 if [[ ${COMP_WORDS[i-1]} != @($global_args) ]]; then
70 71 cmd="${COMP_WORDS[i]}"
71 72 break
72 73 fi
73 74 fi
74 75 done
75 76
76 77 if [[ "$cur" == -* ]]; then
77 78 # this assumes that there are no commands with spaces in the name
78 79 opts=$(hg -v help $cmd | sed -e '/^ *-/!d; s/ [^- ].*//')
79 80
80 81 COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "$opts" -- "$cur") )
81 82 return
82 83 fi
83 84
84 85 # global options
85 86 case "$prev" in
86 87 -R|--repository)
87 88 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
88 89 return
89 90 ;;
90 91 --cwd)
91 92 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
92 93 return
93 94 ;;
94 95 esac
95 96
96 97 if [ -z "$cmd" ] || [ $COMP_CWORD -eq $i ]; then
97 98 _hg_commands
98 99 return
99 100 fi
100 101
101 102 # canonicalize command name
102 103 cmd=$(hg -q help "$cmd" | sed -e 's/^hg //; s/ .*//; 1q')
103 104
104 105 if [ "$cmd" != status ] && [ "$prev" = -r ] || [ "$prev" = --rev ]; then
105 106 _hg_tags
106 107 return
107 108 fi
108 109
109 110 case "$cmd" in
110 111 help)
111 112 _hg_commands
112 113 ;;
113 114 export|manifest|update)
114 115 _hg_tags
115 116 ;;
116 117 pull|push|outgoing|incoming)
117 118 _hg_paths
118 119 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
119 120 ;;
120 121 paths)
121 122 _hg_paths
122 123 ;;
123 124 add)
124 125 _hg_status "u"
125 126 ;;
126 127 commit)
127 128 _hg_status "mra"
128 129 ;;
129 130 remove)
130 131 _hg_status "r"
131 132 ;;
132 133 forget)
133 134 _hg_status "a"
134 135 ;;
135 136 diff)
136 137 _hg_status "mra"
137 138 ;;
138 139 revert)
139 140 _hg_status "mra"
140 141 ;;
141 142 clone)
142 143 local count=$(_hg_count_non_option)
143 144 if [ $count = 1 ]; then
144 145 _hg_paths
145 146 fi
146 147 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -d -- "$cur" ))
147 148 ;;
148 149 debugindex|debugindexdot)
149 150 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.i" -- "$cur" ))
150 151 ;;
151 152 debugdata)
152 153 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -X "!*.d" -- "$cur" ))
153 154 ;;
154 155 cat)
155 156 local count=$(_hg_count_non_option '-o|--output')
156 157 if [ $count = 2 ]; then
157 158 _hg_tags
158 159 else
159 160 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
160 161 fi
161 162 ;;
162 163 *)
163 164 COMPREPLY=(${COMPREPLY[@]:-} $( compgen -f -- "$cur" ))
164 165 ;;
165 166 esac
166 167
167 168 }
168 169
169 170 complete -o bashdefault -o default -F _hg hg 2> /dev/null \
170 171 || complete -o default -F _hg hg
General Comments 0
You need to be logged in to leave comments. Login now