bash completion: Complete subcommands and their options.
* etc/completion/bash/guix (_guix_complete_subcommand): New function. (_guix_complete_option): Allow completion of subcommand options. (_guix_complete): Use '_guix_complete_subcommand' for "system" and "import".
This commit is contained in:
parent
e9006d06a0
commit
f07f7d8614
|
@ -20,6 +20,15 @@
|
||||||
|
|
||||||
declare _guix_available_packages
|
declare _guix_available_packages
|
||||||
|
|
||||||
|
_guix_complete_subcommand ()
|
||||||
|
{
|
||||||
|
local command="${COMP_WORDS[1]}"
|
||||||
|
local subcommands="$(${COMP_WORDS[0]} $command --help 2> /dev/null \
|
||||||
|
| grep '^ [a-z]' \
|
||||||
|
| sed -e's/^ \+\([a-z-]\+\).*$/\1/g')"
|
||||||
|
COMPREPLY=($(compgen -W "$subcommands" -- "${COMP_WORDS[${#COMP_WORDS[*]} - 1]}"))
|
||||||
|
}
|
||||||
|
|
||||||
_guix_complete_available_package ()
|
_guix_complete_available_package ()
|
||||||
{
|
{
|
||||||
local prefix="$1"
|
local prefix="$1"
|
||||||
|
@ -45,11 +54,16 @@ _guix_complete_installed_package ()
|
||||||
|
|
||||||
_guix_complete_option ()
|
_guix_complete_option ()
|
||||||
{
|
{
|
||||||
local options="$(${COMP_WORDS[0]} ${COMP_WORDS[1]} --help 2> /dev/null \
|
local subcommand
|
||||||
|
case "${COMP_WORDS[2]}" in
|
||||||
|
-*) subcommand="";;
|
||||||
|
[a-z]*) subcommand="${COMP_WORDS[2]}";;
|
||||||
|
esac
|
||||||
|
local options="$(${COMP_WORDS[0]} ${COMP_WORDS[1]} $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[$word_count - 1]}"))
|
COMPREPLY=($(compgen -W "$options" -- "${COMP_WORDS[${#COMP_WORDS[*]} - 1]}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
_guix_is_command ()
|
_guix_is_command ()
|
||||||
|
@ -140,13 +154,13 @@ _guix_complete ()
|
||||||
fi
|
fi
|
||||||
elif _guix_is_command "system"
|
elif _guix_is_command "system"
|
||||||
then
|
then
|
||||||
_guix_complete_file # TODO: complete sub-commands
|
_guix_complete_subcommand
|
||||||
|
elif _guix_is_command "import"
|
||||||
|
then
|
||||||
|
_guix_complete_subcommand
|
||||||
elif _guix_is_command "hash"
|
elif _guix_is_command "hash"
|
||||||
then
|
then
|
||||||
_guix_complete_file
|
_guix_complete_file
|
||||||
elif _guix_is_command "import" # TODO: complete sub-commands
|
|
||||||
then
|
|
||||||
_guix_complete_file
|
|
||||||
else
|
else
|
||||||
_guix_complete_available_package "$word_at_point"
|
_guix_complete_available_package "$word_at_point"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue