comparison contrib/bash_completion @ 1887:913397c27cd8

new command debugcomplete add a new command debugcomplete, it lists all the possible completion for the specified command. make the bash_completion script uses it instead of the awk code
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Sun, 12 Mar 2006 11:32:03 +0100
parents 7e10518b2b9e
children 283d2ab1e020
comparison
equal deleted inserted replaced
1886:d4a3a8a332ab 1887:913397c27cd8
1 shopt -s extglob 1 shopt -s extglob
2
3 _hg_command_list()
4 {
5 "$hg" --debug help 2>/dev/null | \
6 awk -F', ' '/^list of commands:/ {commands=1}
7 commands==1 && /^ [^ ]/ {
8 line = substr($0, 2)
9 colon = index(line, ":")
10 if (colon > 0)
11 line = substr(line, 1, colon-1)
12 n = split(line, aliases)
13 command = aliases[1]
14 if (index(command, "debug") == 1) {
15 for (i=1; i<=n; i++)
16 debug[j++] = aliases[i]
17 next
18 }
19 print command
20 for (i=2; i<=n; i++)
21 if (index(command, aliases[i]) != 1)
22 print aliases[i]
23 }
24 /^global options:/ {exit 0}
25 END {for (i in debug) print debug[i]}'
26 }
27 2
28 _hg_option_list() 3 _hg_option_list()
29 { 4 {
30 "$hg" -v help $1 2>/dev/null | \ 5 "$hg" -v help $1 2>/dev/null | \
31 awk '/^ *-/ { 6 awk '/^ *-/ {
38 } 13 }
39 14
40 15
41 _hg_commands() 16 _hg_commands()
42 { 17 {
43 local all commands result 18 local commands="$("$hg" debugcomplete "$cur")"
44 19 COMPREPLY=(${COMPREPLY[@]:-} $(compgen -W '$commands' -- "$cur"))
45 all=$(_hg_command_list)
46 commands=${all%%$'\n'debug*}
47 result=$(compgen -W '$commands' -- "$cur")
48
49 # hide debug commands from users, but complete them if
50 # there is no other possible command
51 if [ "$result" = "" ]; then
52 local debug
53 debug=debug${all#*$'\n'debug}
54 result=$(compgen -W '$debug' -- "$cur")
55 fi
56
57 COMPREPLY=(${COMPREPLY[@]:-} $result)
58 } 20 }
59 21
60 _hg_paths() 22 _hg_paths()
61 { 23 {
62 local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')" 24 local paths="$("$hg" paths 2>/dev/null | sed -e 's/ = .*$//')"