diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-06-04 17:32:23 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-06-04 23:26:43 +0200 |
| commit | b7bb381ba3740d33652c2a8e7772c17b93b259cc (patch) | |
| tree | 434ef170f7a5badebe72afbd547aeed67af59d58 /etc/completion/bash | |
| parent | e6d9e055ec7e211f462c76642ed1b96bb8a70e81 (diff) | |
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/bash')
| -rw-r--r-- | etc/completion/bash/guix | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index 0333bfc8a2c..650cf1d1ce8 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | # GNU Guix --- Functional package management for GNU | 1 | # GNU Guix --- Functional package management for GNU |
| 2 | # Copyright © 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org> | 2 | # Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org> |
| 3 | # | 3 | # |
| 4 | # This file is part of GNU Guix. | 4 | # This file is part of GNU Guix. |
| 5 | # | 5 | # |
| @@ -115,6 +115,24 @@ _guix_is_dash_m () | |||
| 115 | esac } | 115 | esac } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | _guix_is_dash_C () | ||
| 119 | { | ||
| 120 | [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-C" ] \ | ||
| 121 | || { case "${COMP_WORDS[$COMP_CWORD]}" in | ||
| 122 | --channels=*) true;; | ||
| 123 | *) false;; | ||
| 124 | esac } | ||
| 125 | } | ||
| 126 | |||
| 127 | _guix_is_dash_p () | ||
| 128 | { | ||
| 129 | [ "${COMP_WORDS[$COMP_CWORD - 1]}" = "-p" ] \ | ||
| 130 | || { case "${COMP_WORDS[$COMP_CWORD]}" in | ||
| 131 | --profile=*) true;; | ||
| 132 | *) false;; | ||
| 133 | esac } | ||
| 134 | } | ||
| 135 | |||
| 118 | _guix_complete_file () | 136 | _guix_complete_file () |
| 119 | { | 137 | { |
| 120 | # Let Readline complete file names. | 138 | # Let Readline complete file names. |
| @@ -169,13 +187,28 @@ _guix_complete () | |||
| 169 | fi | 187 | fi |
| 170 | elif _guix_is_command "install" | 188 | elif _guix_is_command "install" |
| 171 | then | 189 | then |
| 172 | _guix_complete_available_package "$word_at_point" | 190 | if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p |
| 191 | then | ||
| 192 | _guix_complete_file | ||
| 193 | else | ||
| 194 | _guix_complete_available_package "$word_at_point" | ||
| 195 | fi | ||
| 173 | elif _guix_is_command "remove" | 196 | elif _guix_is_command "remove" |
| 174 | then | 197 | then |
| 175 | _guix_complete_installed_package "$word_at_point" | 198 | if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p |
| 199 | then | ||
| 200 | _guix_complete_file | ||
| 201 | else | ||
| 202 | _guix_complete_installed_package "$word_at_point" | ||
| 203 | fi | ||
| 176 | elif _guix_is_command "upgrade" | 204 | elif _guix_is_command "upgrade" |
| 177 | then | 205 | then |
| 178 | _guix_complete_installed_package "$word_at_point" | 206 | if _guix_is_dash_L || _guix_is_dash_m || _guix_is_dash_p |
| 207 | then | ||
| 208 | _guix_complete_file | ||
| 209 | else | ||
| 210 | _guix_complete_installed_package "$word_at_point" | ||
| 211 | fi | ||
| 179 | elif _guix_is_command "build" | 212 | elif _guix_is_command "build" |
| 180 | then | 213 | then |
| 181 | if _guix_is_dash_L || _guix_is_dash_m | 214 | if _guix_is_dash_L || _guix_is_dash_m |
| @@ -193,6 +226,18 @@ _guix_complete () | |||
| 193 | 2) _guix_complete_subcommand;; | 226 | 2) _guix_complete_subcommand;; |
| 194 | *) _guix_complete_file;; # TODO: restrict to *.scm | 227 | *) _guix_complete_file;; # TODO: restrict to *.scm |
| 195 | esac | 228 | esac |
| 229 | elif _guix_is_command "pull" | ||
| 230 | then | ||
| 231 | if _guix_is_dash_C || _guix_is_dash_p | ||
| 232 | then | ||
| 233 | _guix_complete_file | ||
| 234 | fi | ||
| 235 | elif _guix_is_command "time-machine" | ||
| 236 | then | ||
| 237 | if _guix_is_dash_C | ||
| 238 | then | ||
| 239 | _guix_complete_file | ||
| 240 | fi | ||
| 196 | elif _guix_is_command "container" | 241 | elif _guix_is_command "container" |
| 197 | then | 242 | then |
| 198 | case $COMP_CWORD in | 243 | case $COMP_CWORD in |
