diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2015-08-20 19:57:33 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2015-08-20 19:57:33 +0200 |
| commit | 4a9999871cc75f2d73d5dc83fbcad88bcaa5b921 (patch) | |
| tree | 8452b8e4b440defff70019a9aa7e608ef143737f /etc | |
| parent | fa96048f0a97b4265b3c52f30a5accf89e96174b (diff) | |
bash completion: Cache the list of subcommands and available packages.
* etc/completion/bash/guix (_guix_complete_available_package): Cache the list
of available packages in '_guix_available_packages' and use it.
(_guix_complete): Cache the list of subcommands in '_guix_subcommands' and
use it.
Diffstat (limited to 'etc')
| -rw-r--r-- | etc/completion/bash/guix | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/etc/completion/bash/guix b/etc/completion/bash/guix index e4d9a497b34..807a0b2e1f0 100644 --- a/etc/completion/bash/guix +++ b/etc/completion/bash/guix | |||
| @@ -18,15 +18,24 @@ | |||
| 18 | 18 | ||
| 19 | # Bash completion for Guix commands. | 19 | # Bash completion for Guix commands. |
| 20 | 20 | ||
| 21 | declare _guix_available_packages | ||
| 22 | |||
| 21 | _guix_complete_available_package () | 23 | _guix_complete_available_package () |
| 22 | { | 24 | { |
| 23 | local prefix="$1" | 25 | local prefix="$1" |
| 24 | local packages="$(${COMP_WORDS[0]} package -A "^$prefix" | cut -f1)" | 26 | if [ -z "$_guix_available_packages" ] |
| 25 | COMPREPLY=($(compgen -W "$packages" -- "$prefix")) | 27 | then |
| 28 | # Cache the complete list because it rarely changes and makes | ||
| 29 | # completion much faster. | ||
| 30 | _guix_available_packages="$(${COMP_WORDS[0]} package -A | cut -f1)" | ||
| 31 | fi | ||
| 32 | COMPREPLY=($(compgen -W "$_guix_available_packages" -- "$prefix")) | ||
| 26 | } | 33 | } |
| 27 | 34 | ||
| 28 | _guix_complete_installed_package () | 35 | _guix_complete_installed_package () |
| 29 | { | 36 | { |
| 37 | # Here we do not cache the list of installed packages because that | ||
| 38 | # may change over time and the list is relatively small anyway. | ||
| 30 | local prefix="$1" | 39 | local prefix="$1" |
| 31 | local packages="$(${COMP_WORDS[0]} package -I "^$prefix" | cut -f1)" | 40 | local packages="$(${COMP_WORDS[0]} package -I "^$prefix" | cut -f1)" |
| 32 | COMPREPLY=($(compgen -W "$packages" -- "$prefix")) | 41 | COMPREPLY=($(compgen -W "$packages" -- "$prefix")) |
| @@ -88,6 +97,8 @@ _guix_complete_file () | |||
| 88 | COMPREPLY=() | 97 | COMPREPLY=() |
| 89 | } | 98 | } |
| 90 | 99 | ||
| 100 | declare _guix_subcommands | ||
| 101 | |||
| 91 | _guix_complete () | 102 | _guix_complete () |
| 92 | { | 103 | { |
| 93 | local word_count=${#COMP_WORDS[*]} | 104 | local word_count=${#COMP_WORDS[*]} |
| @@ -105,8 +116,12 @@ _guix_complete () | |||
| 105 | 116 | ||
| 106 | case $COMP_CWORD in | 117 | case $COMP_CWORD in |
| 107 | 1) | 118 | 1) |
| 108 | local subcommands="$(guix --help | grep '^ ' | cut -c 2-)" | 119 | if [ -z "$_guix_subcommands" ] |
| 109 | COMPREPLY=($(compgen -W "$subcommands" -- "$word_at_point")) | 120 | then |
| 121 | # Cache the list of subcommands to speed things up. | ||
| 122 | _guix_subcommands="$(guix --help | grep '^ ' | cut -c 2-)" | ||
| 123 | fi | ||
| 124 | COMPREPLY=($(compgen -W "$_guix_subcommands" -- "$word_at_point")) | ||
| 110 | ;; | 125 | ;; |
| 111 | *) | 126 | *) |
| 112 | if _guix_is_command "package" | 127 | if _guix_is_command "package" |
