|
1 # Relational pipes |
|
2 # Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) |
|
3 # |
|
4 # This program is free software: you can redistribute it and/or modify |
|
5 # it under the terms of the GNU General Public License as published by |
|
6 # the Free Software Foundation, version 3 of the License. |
|
7 # |
|
8 # This program is distributed in the hope that it will be useful, |
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 # GNU General Public License for more details. |
|
12 # |
|
13 # You should have received a copy of the GNU General Public License |
|
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 |
|
16 _relpipe_in_asn1table_completion() { |
|
17 local w0 w1 w2 w3 |
|
18 |
|
19 COMPREPLY=() |
|
20 w0=${COMP_WORDS[COMP_CWORD]} |
|
21 w1=${COMP_WORDS[COMP_CWORD-1]} |
|
22 w2=${COMP_WORDS[COMP_CWORD-2]} |
|
23 w3=${COMP_WORDS[COMP_CWORD-3]} |
|
24 |
|
25 DATA_TYPE=( |
|
26 "string" |
|
27 "integer" |
|
28 "boolean" |
|
29 ) |
|
30 |
|
31 BOOLEAN_VALUES=( |
|
32 "true" |
|
33 "false" |
|
34 ) |
|
35 |
|
36 MODE=( |
|
37 "string" |
|
38 "boolean" |
|
39 "raw-xml" |
|
40 "line-number" |
|
41 "xpath" |
|
42 ) |
|
43 |
|
44 # FIXME: user must type " and then press TAB otherwise the completion is broken due to the : colon |
|
45 # |
|
46 # can be fixed by global modification of environment variable: |
|
47 # COMP_WORDBREAKS=${COMP_WORDBREAKS//:} |
|
48 # but it will affect other completions (where : is a separator) |
|
49 # |
|
50 # these functions should help: |
|
51 # _get_comp_words_by_ref -n : cur |
|
52 # __ltrim_colon_completions "$cur" |
|
53 # but was not working (despite w0 renamed to cur) |
|
54 XMLNS=( |
|
55 "tag:globalcode.info,2018:relpipe" |
|
56 "http://www.w3.org/1999/xhtml" |
|
57 "http://www.w3.org/2000/svg" |
|
58 "http://www.w3.org/2005/Atom" |
|
59 "http://docbook.org/ns/docbook" |
|
60 ) |
|
61 |
|
62 |
|
63 if [[ "$w1" == "--relation" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
64 elif [[ "$w1" == "--records" && "x$w0" == "x" ]]; then COMPREPLY=("'/'") |
|
65 elif [[ "$w1" == "--attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
66 elif [[ "$w2" == "--attribute" ]]; then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0")) |
|
67 elif [[ "$w3" == "--attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
68 elif [[ "$w1" == "--namespace" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
69 elif [[ "$w2" == "--namespace" ]]; then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0")) |
|
70 elif [[ "$w1" == "--xinclude" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) |
|
71 elif [[ "$w1" == "--mode" ]]; then COMPREPLY=($(compgen -W "${MODE[*]}" -- "$w0")) |
|
72 elif [[ "$w1" == "--raw-xml-nodelist-wrapper" ]]; then COMPREPLY=("'xml'") |
|
73 elif [[ "$w2" == "--raw-xml-nodelist-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
74 elif [[ "$w3" == "--raw-xml-nodelist-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
75 |
|
76 elif [[ "$w1" == "--raw-xml-attribute-wrapper" ]]; then COMPREPLY=("'attribute'") |
|
77 elif [[ "$w2" == "--raw-xml-attribute-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
78 elif [[ "$w3" == "--raw-xml-attribute-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
79 |
|
80 elif [[ "$w1" == "--parser-option" ]]; then COMPREPLY=("''") |
|
81 elif [[ "$w2" == "--parser-option" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
82 |
|
83 else |
|
84 OPTIONS=( |
|
85 "--namespace" |
|
86 "--parser-option" |
|
87 "--relation" |
|
88 "--records" |
|
89 "--name-is-xpath" |
|
90 "--attribute" |
|
91 "--xinclude" |
|
92 "--mode" |
|
93 "--raw-xml-nodelist-wrapper" |
|
94 "--raw-xml-attribute-wrapper" |
|
95 ) |
|
96 COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) |
|
97 fi |
|
98 } |
|
99 |
|
100 complete -F _relpipe_in_asn1table_completion relpipe-in-asn1table |