bash-completion.sh
branchv_0
changeset 2 4b05b16b97e6
parent 0 7b70918c30af
equal deleted inserted replaced
1:23c516259cc5 2:4b05b16b97e6
    20 	w0=${COMP_WORDS[COMP_CWORD]}
    20 	w0=${COMP_WORDS[COMP_CWORD]}
    21 	w1=${COMP_WORDS[COMP_CWORD-1]}
    21 	w1=${COMP_WORDS[COMP_CWORD-1]}
    22 	w2=${COMP_WORDS[COMP_CWORD-2]}
    22 	w2=${COMP_WORDS[COMP_CWORD-2]}
    23 	w3=${COMP_WORDS[COMP_CWORD-3]}
    23 	w3=${COMP_WORDS[COMP_CWORD-3]}
    24 
    24 
    25 	DATA_TYPE=(
    25 	if   [[ "$w1" == "--tcp-port"                      && "x$w0" == "x" ]];    then COMPREPLY=("8080")
    26 		"string"
       
    27 		"integer"
       
    28 		"boolean"
       
    29 	)
       
    30 
       
    31 	INPUT_ATTRIBUTE_POLICY=(
       
    32 		"append"
       
    33 		"prepend"
       
    34 		"auto"
       
    35 	)
       
    36 
       
    37 	# FIXME: user must type " and then press TAB otherwise the completion is broken due to the : colon
       
    38 	#
       
    39 	# can be fixed by global modification of environment variable:
       
    40 	#	COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
       
    41 	# but it will affect other completions (where : is a separator)
       
    42 	#
       
    43 	# these functions should help:
       
    44 	#	_get_comp_words_by_ref -n : cur
       
    45 	#	__ltrim_colon_completions "$cur"
       
    46 	# but was not working (despite w0 renamed to cur)
       
    47 	XMLNS=(
       
    48 		"tag:globalcode.info,2018:relpipe"
       
    49 		"http://www.w3.org/1999/xhtml"
       
    50 		"http://www.w3.org/2000/svg"
       
    51 		"http://www.w3.org/2005/Atom"
       
    52 		"http://docbook.org/ns/docbook"
       
    53 	)
       
    54 
       
    55 
       
    56 	if   [[ "$w1" == "--relation"                      && "x$w0" == "x" ]];    then COMPREPLY=("'.*'")
       
    57 	elif [[ "$w1" == "--where"                         && "x$w0" == "x" ]];    then COMPREPLY=("''")
       
    58 	elif [[ "$w1" == "--xml-attribute"                 && "x$w0" == "x" ]];    then COMPREPLY=("''")
       
    59 	elif [[ "$w1" == "--output-attribute"              && "x$w0" == "x" ]];    then COMPREPLY=("''")
       
    60 	elif [[ "$w2" == "--output-attribute"                               ]];    then COMPREPLY=($(compgen -W "${DATA_TYPE[*]}" -- "$w0"))
       
    61 	elif [[ "$w3" == "--output-attribute"              && "x$w0" == "x" ]];    then COMPREPLY=("''")
       
    62 	elif [[ "$w1" == "--namespace"                     && "x$w0" == "x" ]];    then COMPREPLY=("''")
       
    63 	elif [[ "$w2" == "--namespace"                                      ]];    then COMPREPLY=($(compgen -W "${XMLNS[*]}" -- "$w0"))
       
    64 	elif [[ "$w1" == "--input-attributes"                               ]];    then COMPREPLY=($(compgen -W "${INPUT_ATTRIBUTE_POLICY[*]}" -- "$w0"))
       
    65 	else
    26 	else
    66 		OPTIONS=(
    27 		OPTIONS=(
    67 			"--namespace"
    28 			"--tcp-port"
    68 			"--relation"
       
    69 			"--where"
       
    70 			"--output-attribute"
       
    71 			"--input-attributes"
       
    72 			"--xml-attribute"
       
    73 		)
    29 		)
    74 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    30 		COMPREPLY=($(compgen -W "${OPTIONS[*]}" -- "$w0"))
    75 	fi
    31 	fi
    76 }
    32 }
    77 
    33