author | František Kučera <franta-hg@frantovo.cz> |
Wed, 28 Jul 2021 01:40:05 +0200 | |
branch | v_0 |
changeset 41 | 12acb6c02d32 |
parent 40 | 85b6f13f1088 |
permissions | -rw-r--r-- |
0 | 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 |
||
40
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
62 |
# TODO: introspection: after moving to alt2xml the available options and their values should be provided by the parser |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
63 |
|
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
64 |
PARSER_OPTIONS=( |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
65 |
"encoding" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
66 |
"parse-encapsulated" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
67 |
"tree-style" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
68 |
"tree-with-namespaces" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
69 |
"root-name" |
41
12acb6c02d32
configuration: --parser-option bit-string-symbol-0 bit-string-symbol-1 – custom symbols e.g. .:, -+, \/
František Kučera <franta-hg@frantovo.cz>
parents:
40
diff
changeset
|
70 |
"bit-string-symbol-0" |
12acb6c02d32
configuration: --parser-option bit-string-symbol-0 bit-string-symbol-1 – custom symbols e.g. .:, -+, \/
František Kučera <franta-hg@frantovo.cz>
parents:
40
diff
changeset
|
71 |
"bit-string-symbol-1" |
40
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
72 |
); |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
73 |
|
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
74 |
ENCODINGS=( |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
75 |
"BER" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
76 |
"DER" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
77 |
"CER" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
78 |
"PER" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
79 |
"XER" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
80 |
"ASN.1" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
81 |
); |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
82 |
|
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
83 |
TREE_STYLES=( |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
84 |
"standard" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
85 |
"literal" |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
86 |
) |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
87 |
|
0 | 88 |
|
89 |
if [[ "$w1" == "--relation" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
90 |
elif [[ "$w1" == "--records" && "x$w0" == "x" ]]; then COMPREPLY=("'/'") |
|
91 |
elif [[ "$w1" == "--attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
92 |
elif [[ "$w2" == "--attribute" ]]; then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0")) |
|
93 |
elif [[ "$w3" == "--attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
94 |
elif [[ "$w1" == "--namespace" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
95 |
elif [[ "$w2" == "--namespace" ]]; then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0")) |
|
96 |
elif [[ "$w1" == "--xinclude" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) |
|
97 |
elif [[ "$w1" == "--mode" ]]; then COMPREPLY=($(compgen -W "${MODE[*]}" -- "$w0")) |
|
98 |
elif [[ "$w1" == "--raw-xml-nodelist-wrapper" ]]; then COMPREPLY=("'xml'") |
|
99 |
elif [[ "$w2" == "--raw-xml-nodelist-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
100 |
elif [[ "$w3" == "--raw-xml-nodelist-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
101 |
||
102 |
elif [[ "$w1" == "--raw-xml-attribute-wrapper" ]]; then COMPREPLY=("'attribute'") |
|
103 |
elif [[ "$w2" == "--raw-xml-attribute-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
104 |
elif [[ "$w3" == "--raw-xml-attribute-wrapper" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
105 |
||
40
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
106 |
elif [[ "$w1" == "--parser-option" ]]; then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0")) |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
107 |
elif [[ "$w2" == "--parser-option" && "$w1" == "encoding" ]]; then COMPREPLY=($(compgen -W "${ENCODINGS[*]}" -- "$w0")) |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
108 |
elif [[ "$w2" == "--parser-option" && "$w1" == "parse-encapsulated" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
109 |
elif [[ "$w2" == "--parser-option" && "$w1" == "tree-style" ]]; then COMPREPLY=($(compgen -W "${TREE_STYLES[*]}" -- "$w0")) |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
110 |
elif [[ "$w2" == "--parser-option" && "$w1" == "tree-with-namespaces" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) |
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
111 |
elif [[ "$w2" == "--parser-option" && "$w1" == "root-name" && "x$w0" == "x" ]]; then COMPREPLY=("'asn1'") |
41
12acb6c02d32
configuration: --parser-option bit-string-symbol-0 bit-string-symbol-1 – custom symbols e.g. .:, -+, \/
František Kučera <franta-hg@frantovo.cz>
parents:
40
diff
changeset
|
112 |
elif [[ "$w2" == "--parser-option" && "$w1" == "bit-string-symbol-0" && "x$w0" == "x" ]]; then COMPREPLY=("'0'") |
12acb6c02d32
configuration: --parser-option bit-string-symbol-0 bit-string-symbol-1 – custom symbols e.g. .:, -+, \/
František Kučera <franta-hg@frantovo.cz>
parents:
40
diff
changeset
|
113 |
elif [[ "$w2" == "--parser-option" && "$w1" == "bit-string-symbol-1" && "x$w0" == "x" ]]; then COMPREPLY=("'1'") |
40
85b6f13f1088
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
114 |
|
0 | 115 |
else |
116 |
OPTIONS=( |
|
117 |
"--namespace" |
|
118 |
"--parser-option" |
|
119 |
"--relation" |
|
120 |
"--records" |
|
121 |
"--name-is-xpath" |
|
122 |
"--attribute" |
|
123 |
"--xinclude" |
|
124 |
"--mode" |
|
125 |
"--raw-xml-nodelist-wrapper" |
|
126 |
"--raw-xml-attribute-wrapper" |
|
127 |
) |
|
128 |
COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) |
|
129 |
fi |
|
130 |
} |
|
131 |
||
132 |
complete -F _relpipe_in_asn1table_completion relpipe-in-asn1table |