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