scripts/bash-completion.sh
author František Kučera <franta-hg@frantovo.cz>
Sat, 14 Nov 2020 02:10:31 +0100
changeset 112 bf2240a0471d
permissions -rw-r--r--
Bash completion script
franta-hg@112
     1
# Alt2XML
franta-hg@112
     2
# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
franta-hg@112
     3
#
franta-hg@112
     4
# This program is free software: you can redistribute it and/or modify
franta-hg@112
     5
# it under the terms of the GNU General Public License as published by
franta-hg@112
     6
# the Free Software Foundation, version 3 of the License.
franta-hg@112
     7
#
franta-hg@112
     8
# This program is distributed in the hope that it will be useful,
franta-hg@112
     9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@112
    10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@112
    11
# GNU General Public License for more details.
franta-hg@112
    12
#
franta-hg@112
    13
# You should have received a copy of the GNU General Public License
franta-hg@112
    14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@112
    15
franta-hg@112
    16
_alt2xml_completion() {
franta-hg@112
    17
	local w0 w1 w2 w3
franta-hg@112
    18
franta-hg@112
    19
	COMPREPLY=()
franta-hg@112
    20
	w0=${COMP_WORDS[COMP_CWORD]}
franta-hg@112
    21
	w1=${COMP_WORDS[COMP_CWORD-1]}
franta-hg@112
    22
	w2=${COMP_WORDS[COMP_CWORD-2]}
franta-hg@112
    23
	w3=${COMP_WORDS[COMP_CWORD-3]}
franta-hg@112
    24
franta-hg@112
    25
	BOOLEAN=(
franta-hg@112
    26
		"true"
franta-hg@112
    27
		"false"
franta-hg@112
    28
	)
franta-hg@112
    29
franta-hg@112
    30
	ACTION=(
franta-hg@112
    31
		"xml"
franta-hg@112
    32
		"xpath"
franta-hg@112
    33
		"xslt"
franta-hg@112
    34
	)
franta-hg@112
    35
franta-hg@112
    36
franta-hg@112
    37
	if   [[ "$w1" == "--input-file"	                                    ]];    then compopt -o default; COMPREPLY=()
franta-hg@112
    38
	elif [[ "$w1" == "--system-id"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    39
	elif [[ "$w1" == "--input-url"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    40
	elif [[ "$w1" == "--reader-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    41
	elif [[ "$w2" == "--reader-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    42
	elif [[ "$w1" == "--reader-feature"                && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    43
	elif [[ "$w2" == "--reader-feature"                && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    44
	elif [[ "$w1" == "--reader-namespace-aware"                         ]];    then COMPREPLY=($(compgen -W "${BOOLEAN[*]}" -- "$w0"))
franta-hg@112
    45
	elif [[ "$w1" == "--action"                                         ]];    then COMPREPLY=($(compgen -W "${ACTION[*]}"  -- "$w0"))
franta-hg@112
    46
	elif [[ "$w1" == "--action-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    47
	elif [[ "$w2" == "--action-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    48
	elif [[ "$w1" == "--"                              && "x$w0" == "x" ]];    then COMPREPLY=("''")
franta-hg@112
    49
	else
franta-hg@112
    50
		OPTIONS=(
franta-hg@112
    51
			"--input-file"
franta-hg@112
    52
			"--input-stdin"
franta-hg@112
    53
			"--system-id"
franta-hg@112
    54
			"--input-url"
franta-hg@112
    55
			"--reader-property"
franta-hg@112
    56
			"--reader-feature"
franta-hg@112
    57
			"--reader-namespace-aware"
franta-hg@112
    58
			"--action"
franta-hg@112
    59
			"--action-property"
franta-hg@112
    60
			"--"
franta-hg@112
    61
		)
franta-hg@112
    62
		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
franta-hg@112
    63
	fi
franta-hg@112
    64
}
franta-hg@112
    65
franta-hg@112
    66
complete -F _alt2xml_completion alt2xml