author | František Kučera <franta-hg@frantovo.cz> |
Thu, 31 Dec 2020 01:03:13 +0100 | |
branch | v_0 |
changeset 8 | 9f95cfd68f25 |
parent 4 | c58c7f2d4785 |
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_tr_xpath_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 |
INPUT_ATTRIBUTE_POLICY=( |
|
32 |
"append" |
|
33 |
"prepend" |
|
34 |
"auto" |
|
35 |
) |
|
36 |
||
37 |
# FIXME: user must type " and then press TAB otherwise the completion is broken due to the : colon |
|
38 |
# |
|
39 |
# can be fixed by global modification of environment variable: |
|
40 |
# COMP_WORDBREAKS=${COMP_WORDBREAKS//:} |
|
41 |
# but it will affect other completions (where : is a separator) |
|
42 |
# |
|
43 |
# these functions should help: |
|
44 |
# _get_comp_words_by_ref -n : cur |
|
45 |
# __ltrim_colon_completions "$cur" |
|
46 |
# but was not working (despite w0 renamed to cur) |
|
47 |
XMLNS=( |
|
48 |
"tag:globalcode.info,2018:relpipe" |
|
49 |
"http://www.w3.org/1999/xhtml" |
|
50 |
"http://www.w3.org/2000/svg" |
|
51 |
"http://www.w3.org/2005/Atom" |
|
52 |
"http://docbook.org/ns/docbook" |
|
53 |
) |
|
54 |
||
55 |
||
4
c58c7f2d4785
add current relation name: ../relation-name
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
56 |
if [[ "$w1" == "--relation" && "x$w0" == "x" ]]; then COMPREPLY=("'.*'") |
0 | 57 |
elif [[ "$w1" == "--where" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
58 |
elif [[ "$w1" == "--xml-attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
59 |
elif [[ "$w1" == "--output-attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
60 |
elif [[ "$w2" == "--output-attribute" ]]; then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0")) |
|
61 |
elif [[ "$w3" == "--output-attribute" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
62 |
elif [[ "$w1" == "--namespace" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
|
63 |
elif [[ "$w2" == "--namespace" ]]; then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0")) |
|
64 |
elif [[ "$w1" == "--input-attributes" ]]; then COMPREPLY=($(compgen -W "${INPUT_ATTRIBUTE_POLICY[*]}" -- "$w0")) |
|
65 |
else |
|
66 |
OPTIONS=( |
|
67 |
"--namespace" |
|
68 |
"--relation" |
|
69 |
"--where" |
|
70 |
"--output-attribute" |
|
71 |
"--input-attributes" |
|
72 |
"--xml-attribute" |
|
73 |
) |
|
74 |
COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) |
|
75 |
fi |
|
76 |
} |
|
77 |
||
78 |
complete -F _relpipe_tr_xpath_completion relpipe-tr-xpath |