From 6fba67df1928a62abc7939bd8ff020e998ad8d6b Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 3 Oct 2021 13:15:56 +0200 Subject: bash completion: Consolidate similar $command ‘if’ branches. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/completion/bash/guix (_guix_complete): Combine the ‘upgrade’ and ‘remove’ commands, as well as ‘download’, ‘gc’, and ‘hash’. --- etc/completion/bash/guix | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'etc/completion/bash/guix') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index a9386e7794..112ea789de 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -237,15 +237,7 @@ _guix_complete () else _guix_complete_available_package "$word_at_point" fi - elif [[ "$command" = "remove" ]] - then - if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p - then - _guix_complete_file - else - _guix_complete_installed_package "$word_at_point" - fi - elif [[ "$command" = "upgrade" ]] + elif [[ "$command" = "upgrade" || "$command" = "remove" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p then @@ -272,9 +264,9 @@ _guix_complete () else _guix_complete_available_package "$word_at_point" fi - elif [[ "$command" = "download" ]] + elif [[ "$command" = "download" || "$command" = "gc" || "$command" = "hash" ]] then - _guix_complete_file + _guix_complete_file elif [[ "$command" = "system" ]] then case $COMP_CWORD in @@ -305,9 +297,6 @@ _guix_complete () elif [[ "$command" = "import" ]] then _guix_complete_subcommand - elif [[ "$command" = "hash" || "$command" = "gc" ]] - then - _guix_complete_file elif [[ "$command" = "weather" ]] then if _guix_is_dash_m -- cgit v1.2.3 From 17f76b209ceca9972dcd375d2a0f869abc6d1f26 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 3 Oct 2021 14:02:04 +0200 Subject: bash completion: Append to $COMPREPLY where possible. _guix_complete is always called with a fresh empty array. * etc/completion/bash/guix (_guix_complete_command) (_guix_complete_subcommand, _guix_complete_installed_package) (_guix_complete_option, _guix_complete_pid): Append to $COMPREPLY rather than re-assigning. --- etc/completion/bash/guix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'etc/completion/bash/guix') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index 112ea789de..ea8f76f3e0 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -32,7 +32,7 @@ _guix_complete_command () | grep '^ ' \ | sed '-es/^ *\([a-z-]\+\).*$/\1/g')" fi - COMPREPLY=($(compgen -W "$_guix_commands" -- "$word_at_point")) + COMPREPLY+=($(compgen -W "$_guix_commands" -- "$word_at_point")) } _guix_complete_subcommand () @@ -41,7 +41,7 @@ _guix_complete_subcommand () 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_CWORD]}")) + COMPREPLY+=($(compgen -W "$subcommands" -- "${COMP_WORDS[$COMP_CWORD]}")) } _guix_complete_available_package () @@ -54,7 +54,7 @@ _guix_complete_available_package () _guix_available_packages="$(${COMP_WORDS[0]} package -A 2> /dev/null \ | cut -f1)" fi - COMPREPLY=($(compgen -W "$_guix_available_packages" -- "$prefix")) + COMPREPLY+=($(compgen -W "$_guix_available_packages" -- "$prefix")) } _guix_complete_installed_package () @@ -64,7 +64,7 @@ _guix_complete_installed_package () local prefix="$1" local packages="$(${COMP_WORDS[0]} package -I "^$prefix" 2> /dev/null \ | cut -f1)" - COMPREPLY=($(compgen -W "$packages" -- "$prefix")) + COMPREPLY+=($(compgen -W "$packages" -- "$prefix")) } _guix_complete_option () @@ -79,7 +79,7 @@ _guix_complete_option () | grep '^ \+-' \ | sed -e's/^.*--\([a-zA-Z0-9_-]\+\)\(=\?\).*/--\1\2/g')" compopt -o nospace - COMPREPLY=($(compgen -W "$options" -- "$2")) + COMPREPLY+=($(compgen -W "$options" -- "$2")) } _guix_is_option () @@ -174,7 +174,7 @@ _guix_complete_file () _guix_complete_pid () { local pids="$(cd /proc; echo [0-9]*)" - COMPREPLY=($(compgen -W "$pids" -- "$1")) + COMPREPLY+=($(compgen -W "$pids" -- "$1")) } _guix_complete () -- cgit v1.2.3 From ee5e4779e21b6eaf3229ab4201e731d8dde7e4b2 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 3 Oct 2021 13:26:35 +0200 Subject: bash completion: Complete ‘guix weather’ packages. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/completion/bash/guix (_guix_complete): Complete available package names for ‘guix weather’ when not following ‘-m’. --- etc/completion/bash/guix | 2 ++ 1 file changed, 2 insertions(+) (limited to 'etc/completion/bash/guix') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index ea8f76f3e0..724d35b21f 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -302,6 +302,8 @@ _guix_complete () if _guix_is_dash_m then _guix_complete_file + else + _guix_complete_available_package "$word_at_point" fi else _guix_complete_available_package "$word_at_point" -- cgit v1.2.3 From 9e3355d2a35796276d17af13ac45814dbf6c4203 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 3 Oct 2021 13:50:10 +0200 Subject: bash completion: Complete ‘guix build’ file names. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/completion/bash/guix (_guix_complete_available_package_or_store_file): New function. (_guix_complete): Call it in place of _guix_complete_available_package after the ‘build’ command. --- etc/completion/bash/guix | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'etc/completion/bash/guix') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index 724d35b21f..fcf9482639 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -171,6 +171,18 @@ _guix_complete_file () COMPREPLY=() } +_guix_complete_available_package_or_store_file () +{ + _guix_complete_available_package "$@" + + # The current _guix_complete_file implementation doesn't compose (append to + # COMPREPLY), so we suggest file names only if no package names matched. + if [[ -z "$COMPREPLY" ]] + then + _guix_complete_file # TODO: restrict to store files + fi +} + _guix_complete_pid () { local pids="$(cd /proc; echo [0-9]*)" @@ -251,7 +263,7 @@ _guix_complete () then _guix_complete_file else - _guix_complete_available_package "$word_at_point" + _guix_complete_available_package_or_store_file "$word_at_point" fi elif [[ "$command" = "environment" ]] then -- cgit v1.2.3 From d71cfaea3006bc02dc6d309d916809e1f799f04e Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 3 Oct 2021 13:59:54 +0200 Subject: bash completion: Complete ‘guix size’ file names. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/completion/bash/guix (_guix_complete): Complete store file names after the ‘size’ command. --- etc/completion/bash/guix | 3 +++ 1 file changed, 3 insertions(+) (limited to 'etc/completion/bash/guix') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index fcf9482639..d5ec427e0c 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -279,6 +279,9 @@ _guix_complete () elif [[ "$command" = "download" || "$command" = "gc" || "$command" = "hash" ]] then _guix_complete_file + elif [[ "$command" = "size" ]] + then + _guix_complete_available_package_or_store_file "$word_at_point" elif [[ "$command" = "system" ]] then case $COMP_CWORD in -- cgit v1.2.3 From ed14bc298470f77f4ffacdc315ae87939f81c765 Mon Sep 17 00:00:00 2001 From: Tobias Geerinckx-Rice Date: Sun, 3 Oct 2021 14:47:44 +0200 Subject: bash completion: Fix ‘system’ & ‘container’ subcommands. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * etc/completion/bash/guix (_guix_complete): Count words from the innermost command. --- etc/completion/bash/guix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'etc/completion/bash/guix') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index d5ec427e0c..87d9911e53 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -284,8 +284,8 @@ _guix_complete () _guix_complete_available_package_or_store_file "$word_at_point" elif [[ "$command" = "system" ]] then - case $COMP_CWORD in - 2) _guix_complete_subcommand;; + case $((COMP_CWORD - command_index)) in + 1) _guix_complete_subcommand;; *) _guix_complete_file;; # TODO: restrict to *.scm esac elif [[ "$command" = "pull" ]] @@ -304,9 +304,9 @@ _guix_complete () fi elif [[ "$command" = "container" ]] then - case $COMP_CWORD in - 2) _guix_complete_subcommand;; - 3) _guix_complete_pid "$word_at_point";; + case $((COMP_CWORD - command_index)) in + 1) _guix_complete_subcommand;; + 2) _guix_complete_pid "$word_at_point";; *) _guix_complete_file;; esac elif [[ "$command" = "import" ]] -- cgit v1.2.3