mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-25 05:48:07 -05:00
bash completion: Complete options for the right command.
* etc/completion/bash/guix (_guix_complete_option): Receive two arguments and complete the second based on the first, instead of blindly completing the very last word based on the very first (sub)command. (_guix_complete): Adjust both calls.
This commit is contained in:
parent
80a17aae79
commit
dc3ba8c836
1 changed files with 10 additions and 9 deletions
|
@ -69,16 +69,17 @@ _guix_complete_installed_package ()
|
||||||
|
|
||||||
_guix_complete_option ()
|
_guix_complete_option ()
|
||||||
{
|
{
|
||||||
local subcommand
|
local command="${COMP_WORDS[$1]}"
|
||||||
case "${COMP_WORDS[2]}" in
|
local subcommand="${COMP_WORDS[$(($1 + 1))]}"
|
||||||
-*) subcommand="";;
|
if _guix_is_option "$subcommand"
|
||||||
[a-z]*) subcommand="${COMP_WORDS[2]}";;
|
then
|
||||||
esac
|
subcommand=""
|
||||||
local options="$(${COMP_WORDS[0]} ${COMP_WORDS[1]} $subcommand --help 2> /dev/null \
|
fi
|
||||||
|
local options="$(${COMP_WORDS[0]} $command $subcommand --help 2> /dev/null \
|
||||||
| grep '^ \+-' \
|
| grep '^ \+-' \
|
||||||
| sed -e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')"
|
| sed -e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')"
|
||||||
compopt -o nospace
|
compopt -o nospace
|
||||||
COMPREPLY=($(compgen -W "$options" -- "${COMP_WORDS[${#COMP_WORDS[*]} - 1]}"))
|
COMPREPLY=($(compgen -W "$options" -- "$2"))
|
||||||
}
|
}
|
||||||
|
|
||||||
_guix_is_option ()
|
_guix_is_option ()
|
||||||
|
@ -289,7 +290,7 @@ _guix_complete ()
|
||||||
then
|
then
|
||||||
_guix_complete_file
|
_guix_complete_file
|
||||||
else
|
else
|
||||||
_guix_complete_command
|
_guix_complete_option "$command_index" "$word_at_point"
|
||||||
fi
|
fi
|
||||||
elif [[ "$command" = "container" ]]
|
elif [[ "$command" = "container" ]]
|
||||||
then
|
then
|
||||||
|
@ -319,7 +320,7 @@ _guix_complete ()
|
||||||
if [[ -z "$COMPREPLY" && COMP_CWORD -gt command_index ]] &&
|
if [[ -z "$COMPREPLY" && COMP_CWORD -gt command_index ]] &&
|
||||||
_guix_is_option "$word_at_point"
|
_guix_is_option "$word_at_point"
|
||||||
then
|
then
|
||||||
_guix_complete_option
|
_guix_complete_option "$command_index" "$word_at_point"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue