bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sun, 31 Jan 2021 10:14:12 +0100
branchv_0
changeset 3 e2d61907e75f
parent 0 ea26b3359fed
permissions -rw-r--r--
process body/parts recursively
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
ea26b3359fed 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
ea26b3359fed 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
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
ea26b3359fed 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,
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
ea26b3359fed 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
ea26b3359fed 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/>.
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_in_mimetable_completion() {
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	DATA_TYPE=(
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"string"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"integer"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		"boolean"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	BOOLEAN_VALUES=(
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		"true"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
		"false"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	MODE=(
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
		"string"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
		"boolean"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		"raw-xml"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		"line-number"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		"xpath"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
ea26b3359fed 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
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	#
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	# can be fixed by global modification of environment variable:
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
	#	COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
	# but it will affect other completions (where : is a separator)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	#
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	# these functions should help:
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	#	_get_comp_words_by_ref -n : cur
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	#	__ltrim_colon_completions "$cur"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	# but was not working (despite w0 renamed to cur)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	XMLNS=(
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
		"tag:globalcode.info,2018:relpipe"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		"http://www.w3.org/1999/xhtml"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		"http://www.w3.org/2000/svg"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		"http://www.w3.org/2005/Atom"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
		"http://docbook.org/ns/docbook"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
	)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
	# TODO: introspection: after moving to alt2xml the available options and their values should be provided by the parser
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
	PARSER_OPTIONS=(
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		"root-name"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	);
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
	if   [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
	elif [[ "$w1" == "--records"                       && "x$w0" == "x" ]];    then COMPREPLY=("'/'")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
	elif [[ "$w1" == "--attribute"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
	elif [[ "$w2" == "--attribute"                                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
	elif [[ "$w3" == "--attribute"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	elif [[ "$w1" == "--namespace"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
	elif [[ "$w2" == "--namespace"                                      ]];    then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0"))
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
	elif [[ "$w1" == "--xinclude"                                       ]];    then COMPREPLY=($(compgen -W "${BOOLEAN_VALUES[*]}" -- "$w0"))
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
	elif [[ "$w1" == "--mode"                                           ]];    then COMPREPLY=($(compgen -W "${MODE[*]}" -- "$w0"))
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
	elif [[ "$w1" == "--raw-xml-nodelist-wrapper"                       ]];    then COMPREPLY=("'xml'")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
	elif [[ "$w2" == "--raw-xml-nodelist-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
	elif [[ "$w3" == "--raw-xml-nodelist-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
	elif [[ "$w1" == "--raw-xml-attribute-wrapper"                       ]];    then COMPREPLY=("'attribute'")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
	elif [[ "$w2" == "--raw-xml-attribute-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
	elif [[ "$w3" == "--raw-xml-attribute-wrapper"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
	elif [[ "$w1" == "--parser-option"                                   ]];    then COMPREPLY=($(compgen -W "${PARSER_OPTIONS[*]}" -- "$w0"))
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
	elif [[ "$w2" == "--parser-option"                  && "x$w0" == "x" ]];    then COMPREPLY=("''")
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
	else
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
		OPTIONS=(
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
			"--namespace"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
			"--parser-option"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
			"--relation"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
			"--records"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
			"--name-is-xpath"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
			"--attribute"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
			"--xinclude"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
			"--mode"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
			"--raw-xml-nodelist-wrapper"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
			"--raw-xml-attribute-wrapper"
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
		)
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
	fi
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
}
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
complete -F _relpipe_in_mimetable_completion relpipe-in-mimetable
ea26b3359fed project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
complete -F _relpipe_in_mimetable_completion relpipe-in-jsontable