[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/07: bash completion: Complete options for the right command.
From: |
guix-commits |
Subject: |
03/07: bash completion: Complete options for the right command. |
Date: |
Wed, 16 Jun 2021 06:14:40 -0400 (EDT) |
nckx pushed a commit to branch master
in repository guix.
commit dc3ba8c83602d69294e21d1b0c066f0d89890b56
Author: Tobias Geerinckx-Rice <me@tobias.gr>
AuthorDate: Mon Jun 14 10:58:57 2021 +0200
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.
---
etc/completion/bash/guix | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix
index 2b0ec56..f7d1eeb 100644
--- a/etc/completion/bash/guix
+++ b/etc/completion/bash/guix
@@ -69,16 +69,17 @@ _guix_complete_installed_package ()
_guix_complete_option ()
{
- 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 \
+ local command="${COMP_WORDS[$1]}"
+ local subcommand="${COMP_WORDS[$(($1 + 1))]}"
+ if _guix_is_option "$subcommand"
+ then
+ subcommand=""
+ fi
+ local options="$(${COMP_WORDS[0]} $command $subcommand --help 2> /dev/null
\
| grep '^ \+-' \
| sed
-e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')"
compopt -o nospace
- COMPREPLY=($(compgen -W "$options" -- "${COMP_WORDS[${#COMP_WORDS[*]} -
1]}"))
+ COMPREPLY=($(compgen -W "$options" -- "$2"))
}
_guix_is_option ()
@@ -289,7 +290,7 @@ _guix_complete ()
then
_guix_complete_file
else
- _guix_complete_command
+ _guix_complete_option "$command_index" "$word_at_point"
fi
elif [[ "$command" = "container" ]]
then
@@ -319,7 +320,7 @@ _guix_complete ()
if [[ -z "$COMPREPLY" && COMP_CWORD -gt command_index ]] &&
_guix_is_option "$word_at_point"
then
- _guix_complete_option
+ _guix_complete_option "$command_index" "$word_at_point"
fi
}
- branch master updated (72a5095 -> 111521d), guix-commits, 2021/06/16
- 01/07: gnu: bash-completion: Look in user directories first., guix-commits, 2021/06/16
- 02/07: bash completion: Really support subcommands., guix-commits, 2021/06/16
- 03/07: bash completion: Complete options for the right command.,
guix-commits <=
- 04/07: bash_completion: Complete options for ‘guix environment’., guix-commits, 2021/06/16
- 05/07: gnu: Respect ‘rootdelay’ kernel command-line argument., guix-commits, 2021/06/16
- 07/07: gnu: epson-inkjet-printer-escpr: Update to 1.7.11., guix-commits, 2021/06/16
- 06/07: gnu: cryptsetup: Update LUKS2 comment., guix-commits, 2021/06/16