summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2023-09-08 03:51:26 -0700
committerGitHub <noreply@github.com>2023-09-08 12:51:26 +0200
commit45d149c7d32b616ddf9f1a503506fa22012a10b4 (patch)
tree71f26b7f696652f88acfdc8fcafdc1386065eceb /share
parent8250a085b036af1adac23a8ba1de8af0a2f1fe5b (diff)
downloadspack-45d149c7d32b616ddf9f1a503506fa22012a10b4.tar.gz
spack-45d149c7d32b616ddf9f1a503506fa22012a10b4.tar.bz2
spack-45d149c7d32b616ddf9f1a503506fa22012a10b4.tar.xz
spack-45d149c7d32b616ddf9f1a503506fa22012a10b4.zip
bugfix: only complete aliases for potential aliases (#39887)
Smart alias completion introduced in #39499 wasn't as smart as it needed to be, and would complete any invalid command prefix and some env names with alias names. - [x] don't complete aliases if there are no potential completions e.g., don't convert `spack isnotacommand` -> `spack concretize` - [x] don't complete with an aliases if we're not looking at a top-level subcommand.
Diffstat (limited to 'share')
-rwxr-xr-xshare/spack/bash/spack-completion.bash6
-rwxr-xr-xshare/spack/qa/completion-test.sh3
-rwxr-xr-xshare/spack/spack-completion.bash6
3 files changed, 11 insertions, 4 deletions
diff --git a/share/spack/bash/spack-completion.bash b/share/spack/bash/spack-completion.bash
index d779e90aac..49c691be4c 100755
--- a/share/spack/bash/spack-completion.bash
+++ b/share/spack/bash/spack-completion.bash
@@ -367,8 +367,10 @@ _spack_get_alias() {
# If all commands in COMPREPLY alias to the same thing, set COMPREPLY to
# just the real command, not the aliases.
_spack_compress_aliases() {
- # if there's only one thing, don't bother compressing aliases; complete the alias
- if [ "${#COMPREPLY[@]}" == "1" ]; then
+ # If there are zero or one completions, don't do anything
+ # If this isn't the first argument, bail because aliases currently only apply
+ # to top-level commands.
+ if [ "${#COMPREPLY[@]}" -le "1" ] || [ "$COMP_CWORD" != "1" ]; then
return
fi
diff --git a/share/spack/qa/completion-test.sh b/share/spack/qa/completion-test.sh
index 494a1b1235..1071ed36db 100755
--- a/share/spack/qa/completion-test.sh
+++ b/share/spack/qa/completion-test.sh
@@ -67,6 +67,9 @@ contains 'concretise' _spack_completions spack c
contains 'concretize' _spack_completions spack conc
does_not_contain 'concretise' _spack_completions spack conc
+does_not_contain 'concretize' _spack_completions spack isnotacommand
+does_not_contain 'concretize' _spack_completions spack env isnotacommand
+
# XFAIL: Fails for Python 2.6 because pkg_resources not found?
#contains 'compilers.py' _spack_completions spack unit-test ''
diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash
index e3ddbc45b5..3fb313d8de 100755
--- a/share/spack/spack-completion.bash
+++ b/share/spack/spack-completion.bash
@@ -367,8 +367,10 @@ _spack_get_alias() {
# If all commands in COMPREPLY alias to the same thing, set COMPREPLY to
# just the real command, not the aliases.
_spack_compress_aliases() {
- # if there's only one thing, don't bother compressing aliases; complete the alias
- if [ "${#COMPREPLY[@]}" == "1" ]; then
+ # If there are zero or one completions, don't do anything
+ # If this isn't the first argument, bail because aliases currently only apply
+ # to top-level commands.
+ if [ "${#COMPREPLY[@]}" -le "1" ] || [ "$COMP_CWORD" != "1" ]; then
return
fi