bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sun, 27 Oct 2019 01:21:59 +0200
branchv_0
changeset 5 accf73de6778
child 7 ff69af3c67a3
permissions -rw-r--r--
bash-completion script (bit broken due to the : colons in xmlns)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
# Relational pipes
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
#
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# This program is free software: you can redistribute it and/or modify
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
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
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
# the Free Software Foundation, version 3 of the License.
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
#
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
# This program is distributed in the hope that it will be useful,
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
# GNU General Public License for more details.
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
#
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
# You should have received a copy of the GNU General Public License
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
_relpipe_in_xmltable_completion() {
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
	local w0 w1 w2 w3
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	COMPREPLY=()
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
	w0=${COMP_WORDS[COMP_CWORD]}
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
	DATA_TYPE=(
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
		"string"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
		"integer"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
		"boolean"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
	)
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
	# FIXME: user must type " and then press TAB otherwise the completion is broken due to the : colon
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
	#
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
	# can be fixed by global modification of environment variable:
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	#	COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	# but it will affect other completions (where : is a separator)
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
	#
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	# these functions should help:
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	#	_get_comp_words_by_ref -n : cur
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	#	__ltrim_colon_completions "$cur"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
	# but was not working (despite w0 renamed to cur)
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	XMLNS=(
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
		"tag:globalcode.info,2018:relpipe"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		"http://www.w3.org/1999/xhtml"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		"http://www.w3.org/2000/svg"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		"http://www.w3.org/2005/Atom"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	)
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
	if   [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
	elif [[ "$w1" == "--relation"      && "x$w0" == "x" ]];    then COMPREPLY=("''")
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	elif [[ "$w1" == "--records"       && "x$w0" == "x" ]];    then COMPREPLY=("'/'")
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
	elif [[ "$w1" == "--attribute"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
	elif [[ "$w2" == "--attribute"                      ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
	elif [[ "$w3" == "--attribute"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	elif [[ "$w1" == "--namespace"     && "x$w0" == "x" ]];    then COMPREPLY=("''")
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
	elif [[ "$w2" == "--namespace"                      ]];    then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0"))
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
	else
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		OPTIONS=(
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
			"--namespace"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
			"--relation"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
			"--records"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
			"--name-is-xpath"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
			"--attribute"
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		)
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
	fi
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
}
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
accf73de6778 bash-completion script (bit broken due to the : colons in xmlns)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
complete -F _relpipe_in_xmltable_completion relpipe-in-xmltable