scripts/bash-completion.sh
changeset 112 bf2240a0471d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/scripts/bash-completion.sh	Sat Nov 14 02:10:31 2020 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +# Alt2XML
     1.5 +# Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
     1.6 +#
     1.7 +# This program is free software: you can redistribute it and/or modify
     1.8 +# it under the terms of the GNU General Public License as published by
     1.9 +# the Free Software Foundation, version 3 of the License.
    1.10 +#
    1.11 +# This program is distributed in the hope that it will be useful,
    1.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    1.14 +# GNU General Public License for more details.
    1.15 +#
    1.16 +# You should have received a copy of the GNU General Public License
    1.17 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
    1.18 +
    1.19 +_alt2xml_completion() {
    1.20 +	local w0 w1 w2 w3
    1.21 +
    1.22 +	COMPREPLY=()
    1.23 +	w0=${COMP_WORDS[COMP_CWORD]}
    1.24 +	w1=${COMP_WORDS[COMP_CWORD-1]}
    1.25 +	w2=${COMP_WORDS[COMP_CWORD-2]}
    1.26 +	w3=${COMP_WORDS[COMP_CWORD-3]}
    1.27 +
    1.28 +	BOOLEAN=(
    1.29 +		"true"
    1.30 +		"false"
    1.31 +	)
    1.32 +
    1.33 +	ACTION=(
    1.34 +		"xml"
    1.35 +		"xpath"
    1.36 +		"xslt"
    1.37 +	)
    1.38 +
    1.39 +
    1.40 +	if   [[ "$w1" == "--input-file"	                                    ]];    then compopt -o default; COMPREPLY=()
    1.41 +	elif [[ "$w1" == "--system-id"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.42 +	elif [[ "$w1" == "--input-url"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.43 +	elif [[ "$w1" == "--reader-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.44 +	elif [[ "$w2" == "--reader-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.45 +	elif [[ "$w1" == "--reader-feature"                && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.46 +	elif [[ "$w2" == "--reader-feature"                && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.47 +	elif [[ "$w1" == "--reader-namespace-aware"                         ]];    then COMPREPLY=($(compgen -W "${BOOLEAN[*]}" -- "$w0"))
    1.48 +	elif [[ "$w1" == "--action"                                         ]];    then COMPREPLY=($(compgen -W "${ACTION[*]}"  -- "$w0"))
    1.49 +	elif [[ "$w1" == "--action-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.50 +	elif [[ "$w2" == "--action-property"               && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.51 +	elif [[ "$w1" == "--"                              && "x$w0" == "x" ]];    then COMPREPLY=("''")
    1.52 +	else
    1.53 +		OPTIONS=(
    1.54 +			"--input-file"
    1.55 +			"--input-stdin"
    1.56 +			"--system-id"
    1.57 +			"--input-url"
    1.58 +			"--reader-property"
    1.59 +			"--reader-feature"
    1.60 +			"--reader-namespace-aware"
    1.61 +			"--action"
    1.62 +			"--action-property"
    1.63 +			"--"
    1.64 +		)
    1.65 +		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    1.66 +	fi
    1.67 +}
    1.68 +
    1.69 +complete -F _alt2xml_completion alt2xml