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