author | František Kučera <franta-hg@frantovo.cz> |
Tue, 11 May 2021 20:42:22 +0200 | |
branch | v_0 |
changeset 25 | 98be80d2e65b |
parent 24 | c69670b7b4ef |
child 26 | 88e566898f8f |
permissions | -rw-r--r-- |
24
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
# Relational pipes |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
# Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
# |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
# This program is free software: you can redistribute it and/or modify |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
# it under the terms of the GNU General Public License as published by |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
# the Free Software Foundation, version 3 of the License. |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
# |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
# This program is distributed in the hope that it will be useful, |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
# GNU General Public License for more details. |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
# |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
# You should have received a copy of the GNU General Public License |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
|
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
_relpipe_tr_grep_completion() { |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
local w0 w1 w2 w3 |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
COMPREPLY=() |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
w0=${COMP_WORDS[COMP_CWORD]} |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
w1=${COMP_WORDS[COMP_CWORD-1]} |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
w2=${COMP_WORDS[COMP_CWORD-2]} |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
w3=${COMP_WORDS[COMP_CWORD-3]} |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
|
25
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
25 |
BOOLEAN_VALUES=( |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
26 |
"true" |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
27 |
"false" |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
28 |
) |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
29 |
|
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
30 |
ENTITY_VALUES=( |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
31 |
"relation" |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
32 |
"attribute" |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
33 |
"value" |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
34 |
) |
24
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
if [[ "$w1" == "--relation" && "x$w0" == "x" ]]; then COMPREPLY=("'.*'") |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
elif [[ "$w1" == "--attribute" && "x$w0" == "x" ]]; then COMPREPLY=("'.*'") |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
elif [[ "$w1" == "--pattern" && "x$w0" == "x" ]]; then COMPREPLY=("''") |
25
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
39 |
elif [[ "$w1" == "--case-sensitive" ]]; then COMPREPLY=($(compgen -W "${ENTITY_VALUES[*]}" -- "$w0")) |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
40 |
elif [[ "$w2" == "--case-sensitive" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
41 |
elif [[ "$w1" == "--invert-match" ]]; then COMPREPLY=($(compgen -W "${ENTITY_VALUES[*]}" -- "$w0")) |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
42 |
elif [[ "$w2" == "--invert-match" ]]; then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0")) |
24
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
else |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
OPTIONS=( |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
"--relation" |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
"--attribute" |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
"--pattern" |
25
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
48 |
"--case-sensitive" |
98be80d2e65b
new CLI options: --case-sensitive, --invert-match
František Kučera <franta-hg@frantovo.cz>
parents:
24
diff
changeset
|
49 |
"--invert-match" |
24
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
) |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0")) |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
fi |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
} |
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
|
c69670b7b4ef
new CLI interface: --relation, --attribute, --pattern
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
complete -F _relpipe_tr_grep_completion relpipe-tr-grep |