guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: bash completion: Complete file names after '-p' and '-C'.


From: guix-commits
Subject: 01/03: bash completion: Complete file names after '-p' and '-C'.
Date: Thu, 4 Jun 2020 17:27:59 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit b7bb381ba3740d33652c2a8e7772c17b93b259cc
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Thu Jun 4 17:32:23 2020 +0200

    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(-)

diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix
index 0333bfc..650cf1d 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 <ludo@gnu.org>
+# Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
 #
 # 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]