From b7bb381ba3740d33652c2a8e7772c17b93b259cc Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 4 Jun 2020 17:32:23 +0200 Subject: bash completion: Complete file names after '-p' and '-C'. * etc/completion/bash/guix (_guix_is_dash_C, _guix_is_dash_p): New functions. (_guix_complete): Honor them for "install", "remove", "upgrade", "pull", and "time-machine". --- etc/completion/bash/guix | 53 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'etc') diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index 0333bfc8a2..650cf1d1ce 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2015, 2016, 2017, 2018, 2019 Ludovic Courtès +# Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès # # This file is part of GNU Guix. # @@ -115,6 +115,24 @@ _guix_is_dash_m () esac } } +_guix_is_dash_C () +{ + [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-C" ] \ + || { case "${COMP_WORDS[$COMP_CWORD]}" in + --channels=*) true;; + *) false;; + esac } +} + +_guix_is_dash_p () +{ + [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-p" ] \ + || { case "${COMP_WORDS[$COMP_CWORD]}" in + --profile=*) true;; + *) false;; + esac } +} + _guix_complete_file () { # Let Readline complete file names. @@ -169,13 +187,28 @@ _guix_complete () fi elif _guix_is_command "install" then - _guix_complete_available_package "$word_at_point" + if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p + then + _guix_complete_file + else + _guix_complete_available_package "$word_at_point" + fi elif _guix_is_command "remove" then - _guix_complete_installed_package "$word_at_point" + 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 _guix_is_command "upgrade" then - _guix_complete_installed_package "$word_at_point" + 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 _guix_is_command "build" then if _guix_is_dash_L || _guix_is_dash_m @@ -193,6 +226,18 @@ _guix_complete () 2) _guix_complete_subcommand;; *) _guix_complete_file;; # TODO: restrict to *.scm esac + elif _guix_is_command "pull" + then + if _guix_is_dash_C || _guix_is_dash_p + then + _guix_complete_file + fi + elif _guix_is_command "time-machine" + then + if _guix_is_dash_C + then + _guix_complete_file + fi elif _guix_is_command "container" then case $COMP_CWORD in -- cgit v1.2.3