[Bash-Completion] Fix bash completon for files paths
Changes: * fix for command `rally task start --task [TAB]' - now it shows filepaths choices * introduces function _rally_filedir as replacement for _filedir - this fixes issue `._filedir: command not found' in case if /etc/bash_completion routines are not loaded * small refactoring in rally bash completion Change-Id: Ib5e15a20c52ba3ccec32424d9404d2a929d82958 Closes-Bug: #1470006
This commit is contained in:
parent
3d9da81f9c
commit
d24fd8ba0d
@ -1,6 +1,18 @@
|
|||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Standalone _filedir() alternative.
|
||||||
|
# This exempts from dependence of bash completion routines
|
||||||
|
function _rally_filedir()
|
||||||
|
{
|
||||||
|
test "${1}" \
|
||||||
|
&& COMPREPLY=( \
|
||||||
|
$(compgen -f -- "${cur}" | grep -E "${1}") \
|
||||||
|
$(compgen -o plusdirs -- "${cur}") ) \
|
||||||
|
|| COMPREPLY=( \
|
||||||
|
$(compgen -o plusdirs -f -- "${cur}") \
|
||||||
|
$(compgen -d -- "${cur}") )
|
||||||
|
}
|
||||||
|
|
||||||
_rally()
|
_rally()
|
||||||
{
|
{
|
||||||
declare -A SUBCOMMANDS
|
declare -A SUBCOMMANDS
|
||||||
@ -44,7 +56,6 @@ _rally()
|
|||||||
OPTS["verify_start"]="--deployment --set --regex --tempest-config --no-use"
|
OPTS["verify_start"]="--deployment --set --regex --tempest-config --no-use"
|
||||||
OPTS["verify_use"]="--verification"
|
OPTS["verify_use"]="--verification"
|
||||||
|
|
||||||
|
|
||||||
for OPT in ${!OPTS[*]} ; do
|
for OPT in ${!OPTS[*]} ; do
|
||||||
CMD=${OPT%%_*}
|
CMD=${OPT%%_*}
|
||||||
CMDSUB=${OPT#*_}
|
CMDSUB=${OPT#*_}
|
||||||
@ -57,22 +68,19 @@ _rally()
|
|||||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
local prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
|
|
||||||
if [[ $cur =~ (\.|\~|\/).* ]] ; then
|
if [[ $cur =~ ^(\.|\~|\/) ]] || [[ $prev =~ ^--out(|put-file)$ ]] ; then
|
||||||
_filedir
|
_rally_filedir
|
||||||
|
elif [[ $prev =~ ^--(task|filename)$ ]] ; then
|
||||||
|
_rally_filedir "\.json|\.yaml|\.yml"
|
||||||
elif [ $COMP_CWORD == "1" ] ; then
|
elif [ $COMP_CWORD == "1" ] ; then
|
||||||
COMPREPLY=($(compgen -W "$COMMANDS" -- ${cur}))
|
COMPREPLY=($(compgen -W "$COMMANDS" -- ${cur}))
|
||||||
elif [ $COMP_CWORD == "2" ] ; then
|
elif [ $COMP_CWORD == "2" ] ; then
|
||||||
COMPREPLY=($(compgen -W "${SUBCOMMANDS[${prev}]}" -- ${cur}))
|
COMPREPLY=($(compgen -W "${SUBCOMMANDS[${prev}]}" -- ${cur}))
|
||||||
else
|
else
|
||||||
if [ $prev == "--filename" ] ; then
|
COMMAND="${COMP_WORDS[1]}_${COMP_WORDS[2]}"
|
||||||
_filedir "@(json|ya?ml)"
|
COMPREPLY=($(compgen -W "${OPTS[$COMMAND]}" -- ${cur}))
|
||||||
elif [ $prev == "--output-file" ] || [ $prev == "--out" ]; then
|
|
||||||
_filedir
|
|
||||||
else
|
|
||||||
COMMAND="${COMP_WORDS[1]}_${COMP_WORDS[2]}"
|
|
||||||
COMPREPLY=($(compgen -W "${OPTS[$COMMAND]}" -- ${cur}))
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
complete -F _rally rally
|
|
||||||
|
complete -o filenames -F _rally rally
|
||||||
|
Loading…
Reference in New Issue
Block a user