diff options
author | Marius Bakke <marius@gnu.org> | 2021-06-19 17:38:47 +0200 |
---|---|---|
committer | Marius Bakke <marius@gnu.org> | 2021-06-19 17:38:47 +0200 |
commit | 6f9a80b331ae41d142a49fbeb94b90ee587b6155 (patch) | |
tree | 2da042a6ccf5368c73d6e3d54c2ee02a62d284e4 /etc/completion/bash/guix | |
parent | 6500c9a5b364616e38a7e03aa4516fc2d7cee876 (diff) | |
parent | dece03e2b98fc1c2428c2448ce5792f813eb79bf (diff) |
Merge branch 'master' into core-updates
Note: this merge actually changes the 'curl' and 'python-attrs' derivations,
as part of solving caf4a7a2770ef4d05a6e18f40d602e51da749ddc and
12964df69a99de6190422c752fef65ef813f3b6b respectively.
4604d43c0e (gnu: gnutls@3.6.16: Fix cross-compilation.) was ignored because it
cannot currently be tested.
Conflicts:
gnu/local.mk
gnu/packages/aidc.scm
gnu/packages/boost.scm
gnu/packages/curl.scm
gnu/packages/nettle.scm
gnu/packages/networking.scm
gnu/packages/python-xyz.scm
gnu/packages/tls.scm
Diffstat (limited to 'etc/completion/bash/guix')
-rw-r--r-- | etc/completion/bash/guix | 117 |
1 files changed, 73 insertions, 44 deletions
diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index 26480e5863..a9386e7794 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -1,5 +1,6 @@ # GNU Guix --- Functional package management for GNU # Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> +# Copyright © 2021 Tobias Geerinck-Rice <me@tobias.gr> # # This file is part of GNU Guix. # @@ -68,31 +69,29 @@ _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_command () +_guix_is_option () { - local word - local result="false" - for word in ${COMP_WORDS[*]} - do - if [ "$word" = "$1" ] - then - result=true - break - fi - done - $result + case "$1" in + -*) + true + ;; + *) + false + ;; + esac } _guix_is_removing () @@ -183,22 +182,43 @@ _guix_complete () local word_count=${#COMP_WORDS[*]} local word_at_point="${COMP_WORDS[$COMP_CWORD]}" - if [ "$COMP_CWORD" -gt 1 ] - then - case "$word_at_point" in - -*) - _guix_complete_option "$word_at_point" - return - ;; - esac - fi + # Find the innermost command at point, e.g. "build" in the case of + # "guix time-machine OPTIONS -- build<Tab>" -- but "time-machine" if + # point is moved before "build". + local command_index=0 + local command + local word_index=0 + local word + local expect_command="true" + while [[ $((++word_index)) -le COMP_CWORD ]] + do + word="${COMP_WORDS[$word_index]}" + if $expect_command + then + command_index=$word_index + command="$word" + expect_command="false" + continue + fi + if [[ "$word" = "--" ]] + then + case "$command" in + environment) + break + ;; + time-machine) + expect_command="true" + ;; + esac + fi + done case $COMP_CWORD in - 1) + $command_index) _guix_complete_command ;; *) - if _guix_is_command "package" + if [[ "$command" = "package" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p || _guix_is_dash_f then @@ -209,7 +229,7 @@ _guix_complete () else _guix_complete_available_package "$word_at_point" fi - elif _guix_is_command "install" + elif [[ "$command" = "install" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p then @@ -217,7 +237,7 @@ _guix_complete () else _guix_complete_available_package "$word_at_point" fi - elif _guix_is_command "remove" + elif [[ "$command" = "remove" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p then @@ -225,7 +245,7 @@ _guix_complete () else _guix_complete_installed_package "$word_at_point" fi - elif _guix_is_command "upgrade" + elif [[ "$command" = "upgrade" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p then @@ -233,7 +253,7 @@ _guix_complete () else _guix_complete_installed_package "$word_at_point" fi - elif _guix_is_command "build" + elif [[ "$command" = "build" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_f then @@ -241,51 +261,54 @@ _guix_complete () else _guix_complete_available_package "$word_at_point" fi - elif _guix_is_command "environment" + elif [[ "$command" = "environment" ]] then if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p || _guix_is_dash_l then _guix_complete_file + elif _guix_is_option "$word_at_point" + then + _guix_complete_option "$command_index" "$word_at_point" else _guix_complete_available_package "$word_at_point" fi - elif _guix_is_command "download" + elif [[ "$command" = "download" ]] then _guix_complete_file - elif _guix_is_command "system" + elif [[ "$command" = "system" ]] then case $COMP_CWORD in 2) _guix_complete_subcommand;; *) _guix_complete_file;; # TODO: restrict to *.scm esac - elif _guix_is_command "pull" + elif [[ "$command" = "pull" ]] then if _guix_is_dash_C || _guix_is_dash_p then _guix_complete_file fi - elif _guix_is_command "time-machine" + elif [[ "$command" = "time-machine" ]] then if _guix_is_dash_C then _guix_complete_file else - _guix_complete_command + _guix_complete_option "$command_index" "$word_at_point" fi - elif _guix_is_command "container" + elif [[ "$command" = "container" ]] then case $COMP_CWORD in 2) _guix_complete_subcommand;; 3) _guix_complete_pid "$word_at_point";; *) _guix_complete_file;; esac - elif _guix_is_command "import" + elif [[ "$command" = "import" ]] then _guix_complete_subcommand - elif _guix_is_command "hash" || _guix_is_command "gc" + elif [[ "$command" = "hash" || "$command" = "gc" ]] then _guix_complete_file - elif _guix_is_command "weather" + elif [[ "$command" = "weather" ]] then if _guix_is_dash_m then @@ -296,6 +319,12 @@ _guix_complete () fi ;; esac + + if [[ -z "$COMPREPLY" && COMP_CWORD -gt command_index ]] && + _guix_is_option "$word_at_point" + then + _guix_complete_option "$command_index" "$word_at_point" + fi } complete -F _guix_complete guix |