1 |
commit: da5fba4f2bc976c573bf658e05fe0f854796dbf6 |
2 |
Author: Ryan Hill <dirtyepic <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Nov 3 05:52:22 2012 +0000 |
4 |
Commit: Ryan Hill <dirtyepic <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Nov 3 05:52:22 2012 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-bashcomp.git;a=commit;h=da5fba4f |
7 |
|
8 |
Make layman completion work again. |
9 |
|
10 |
Sometime in the last three years the output of layman changed and broke |
11 |
the overlay parsing. Also updated options, fixed handling of opts |
12 |
containing "=" with bash-4, and cleaned up a bunch of stuff. |
13 |
|
14 |
--- |
15 |
layman | 93 +++++++++++++++++++++++++++++++--------------------------------- |
16 |
1 files changed, 45 insertions(+), 48 deletions(-) |
17 |
|
18 |
diff --git a/layman b/layman |
19 |
index 0463f9a..40219f8 100644 |
20 |
--- a/layman |
21 |
+++ b/layman |
22 |
@@ -9,66 +9,63 @@ |
23 |
# Originally written by: Peter "Link" Sterk <link@××××××××××××××××××.org> |
24 |
|
25 |
|
26 |
-have layman && { |
27 |
- _layman() |
28 |
- { |
29 |
- local cur prev opts r_overlays l_overlays |
30 |
- opts="-a --add -d --delete -s --sync -i --info -S --sync-all -L --list \ |
31 |
- -l --list-local -f --fetch -n --nofetch -p --priority -c --config \ |
32 |
- -o --overlays -v --verbose -q --quiet -N --nocolor -Q --quietness \ |
33 |
- -k --nocheck --debug --debug-level --debug-verbose --debug-methods \ |
34 |
- --debug-classes --debug-variables --debug-class-vars --debug-nocolor" |
35 |
+have layman && |
36 |
+_layman() { |
37 |
+ local cur prev opts r_overlays l_overlays splitopt |
38 |
|
39 |
- r_overlays="$(layman -LkN 2>/dev/null | grep '(source' | awk '{print $2}')" |
40 |
- l_overlays="$(layman -lkN 2>/dev/null | grep '(source' | awk '{print $2}')" |
41 |
- ls_overlays="${l_overlays} ALL" |
42 |
+ COMPREPLY=() |
43 |
|
44 |
- COMPREPLY=() |
45 |
+ opts="--version -h --help -a --add -d --delete -s --sync -i --info |
46 |
+ -S --sync-all -L --list -l --list-local -n --nofetch -p --priority |
47 |
+ -c --config -O --overlay_defs -o --overlays -v --verbose -q --quiet |
48 |
+ -N --nocolor -Q --quietness -W --width -k --nocheck --debug-level" |
49 |
+ r_overlays="$(layman -LkNq 2>/dev/null | grep -v '^$' | cut -d' ' -f3)" |
50 |
+ l_overlays="$(layman -lkNq 2>/dev/null | grep -v '^$' | cut -d' ' -f3)" |
51 |
+ splitopt=false |
52 |
|
53 |
- cur="${COMP_WORDS[COMP_CWORD]}" |
54 |
- prev="${COMP_WORDS[COMP_CWORD-1]}" |
55 |
+ _get_comp_words_by_ref -n = cur prev |
56 |
+ _split_longopt && splitopt=true |
57 |
|
58 |
- if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] |
59 |
- then |
60 |
- COMPREPLY=($(compgen -W "${opts}" -- ${cur})) |
61 |
+ case ${prev} in |
62 |
+ --version|-h|--help|-W|--width|-o|--overlays) |
63 |
+ # these end processing or require an arg we can't complete on |
64 |
return 0 |
65 |
- fi |
66 |
- |
67 |
- case "${prev}" in |
68 |
- -a|--add) |
69 |
- COMPREPLY=($(compgen -W "${r_overlays}" -- ${cur})) |
70 |
- return 0 |
71 |
;; |
72 |
- -d|--delete) |
73 |
- COMPREPLY=($(compgen -W "${l_overlays}" -- "${cur}")) |
74 |
- return 0 |
75 |
+ -a|--add|-i|--info) |
76 |
+ COMPREPLY=( $(compgen -W "${r_overlays}" -- "${cur}") ) |
77 |
+ return 0 |
78 |
;; |
79 |
- -s|--sync) |
80 |
- COMPREPLY=($(compgen -W "${ls_overlays}" -- "${cur}")) |
81 |
- return 0 |
82 |
+ -d|--delete) |
83 |
+ COMPREPLY=( $(compgen -W "${l_overlays}" -- "${cur}") ) |
84 |
+ return 0 |
85 |
;; |
86 |
- -i|--info) |
87 |
- COMPREPLY=($(compgen -W "${r_overlays}" -- "${cur}")) |
88 |
- return 0 |
89 |
+ -s|--sync) |
90 |
+ COMPREPLY=( $(compgen -W "${l_overlays} ALL" -- "${cur}") ) |
91 |
+ return 0 |
92 |
;; |
93 |
- -p|--priority) |
94 |
- COMPREPLY=($(compgen -W "$(seq 0 100)" -- "${cur}")) |
95 |
- return 0 |
96 |
+ -p|--priority) |
97 |
+ # this seems excessive |
98 |
+ COMPREPLY=( $(compgen -W "$(seq 0 100)" -- "${cur}") ) |
99 |
+ return 0 |
100 |
;; |
101 |
- -Q|--quietness) |
102 |
- COMPREPLY=($(compgen -W "$(seq 0 4)" -- "${cur}")) |
103 |
- return 0 |
104 |
+ -Q|--quietness) |
105 |
+ COMPREPLY=( $(compgen -W "$(seq 0 4)" -- "${cur}") ) |
106 |
+ return 0 |
107 |
;; |
108 |
- --debug-level) |
109 |
- COMPREPLY=($(compgen -W "$(seq 0 10)" -- "${cur}")) |
110 |
- return 0 |
111 |
+ --debug-level) |
112 |
+ COMPREPLY=( $(compgen -W "$(seq 0 10)" -- "${cur}") ) |
113 |
+ return 0 |
114 |
;; |
115 |
- --debug-verbose) |
116 |
- COMPREPLY=($(compgen -W "$(seq 1 3)" -- "${cur}")) |
117 |
- return 0 |
118 |
+ -c|--config|-O|--overlay_defs) |
119 |
+ _filedir |
120 |
+ return 0 |
121 |
;; |
122 |
- esac |
123 |
- } |
124 |
- complete -F _layman layman |
125 |
+ esac |
126 |
+ |
127 |
+ $splitopt && return 0 |
128 |
+ |
129 |
+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) |
130 |
} |
131 |
+complete -F _layman layman |
132 |
+ |
133 |
# vim: ft=sh:et:ts=4:sw=4:tw=80 |