summary refs log tree commit diff
path: root/etc/completion
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2020-06-04 17:32:23 +0200
committerLudovic Courtès <ludo@gnu.org>2020-06-04 23:26:43 +0200
commitb7bb381ba3740d33652c2a8e7772c17b93b259cc (patch)
tree434ef170f7a5badebe72afbd547aeed67af59d58 /etc/completion
parente6d9e055ec7e211f462c76642ed1b96bb8a70e81 (diff)
downloadguix-b7bb381ba3740d33652c2a8e7772c17b93b259cc.tar.gz
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".
Diffstat (limited to 'etc/completion')
-rw-r--r--etc/completion/bash/guix53
1 files changed, 49 insertions, 4 deletions
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 <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