bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Thu, 22 Jul 2021 20:01:03 +0200
branchv_0
changeset 40 85b6f13f1088
parent 0 bfee08a31fdc
child 41 12acb6c02d32
permissions -rw-r--r--
configuration: --parser-option encoding, parse-encapsulated, root-name, tree-style, tree-with-namespaces
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
bfee08a31fdc project skeleton
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
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_in_asn1table_completion() {
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	DATA_TYPE=(
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"string"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"integer"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		"boolean"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	BOOLEAN_VALUES=(
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		"true"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		"false"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	MODE=(
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		"string"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		"boolean"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		"raw-xml"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		"line-number"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		"xpath"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	# FIXME: user must type " and then press TAB otherwise the completion is broken due to the : colon
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	#
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	# can be fixed by global modification of environment variable:
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	#	COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	# but it will affect other completions (where : is a separator)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	#
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	# these functions should help:
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	#	_get_comp_words_by_ref -n : cur
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	#	__ltrim_colon_completions "$cur"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	# but was not working (despite w0 renamed to cur)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	XMLNS=(
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		"tag:globalcode.info,2018:relpipe"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		"http://www.w3.org/1999/xhtml"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		"http://www.w3.org/2000/svg"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		"http://www.w3.org/2005/Atom"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		"http://docbook.org/ns/docbook"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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"
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
    70
	);
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
    71
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
	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
    73
		"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
    74
		"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
    75
		"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
    76
		"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
    77
		"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
    78
		"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
    79
	);
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
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
	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
    82
		"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
    83
		"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
    84
	)
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
0
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
	if   [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
	elif [[ "$w1" == "--records"                       && "x$w0" == "x" ]];    then COMPREPLY=("'/'")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
	elif [[ "$w1" == "--attribute"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
	elif [[ "$w2" == "--attribute"                                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
	elif [[ "$w3" == "--attribute"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
	elif [[ "$w1" == "--namespace"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
	elif [[ "$w2" == "--namespace"                                      ]];    then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0"))
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
	elif [[ "$w1" == "--xinclude"                                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
	elif [[ "$w1" == "--mode"                                           ]];    then COMPREPLY=($(compgen -W "${MODE[*]}" -- "$w0"))
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
	elif [[ "$w1" == "--raw-xml-nodelist-wrapper"                       ]];    then COMPREPLY=("'xml'")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
	elif [[ "$w2" == "--raw-xml-nodelist-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
	elif [[ "$w3" == "--raw-xml-nodelist-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
	elif [[ "$w1" == "--raw-xml-attribute-wrapper"                       ]];    then COMPREPLY=("'attribute'")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
	elif [[ "$w2" == "--raw-xml-attribute-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
	elif [[ "$w3" == "--raw-xml-attribute-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
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
   104
	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
   105
	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
   106
	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
   107
	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
   108
	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
   109
	elif [[ "$w2" == "--parser-option" && "$w1" == "root-name"               && "x$w0" == "x" ]];    then COMPREPLY=("'asn1'")
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
	
0
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   111
	else
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   112
		OPTIONS=(
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
			"--namespace"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
			"--parser-option"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
			"--relation"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
			"--records"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
			"--name-is-xpath"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   118
			"--attribute"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
			"--xinclude"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
			"--mode"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
			"--raw-xml-nodelist-wrapper"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
			"--raw-xml-attribute-wrapper"
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
		)
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   124
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   125
	fi
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
}
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
bfee08a31fdc project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   128
complete -F _relpipe_in_asn1table_completion relpipe-in-asn1table