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.
This commit is contained in:
Todd Gamblin 2023-09-08 03:51:26 -07:00 committed by GitHub
parent 8250a085b0
commit 45d149c7d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 4 deletions

View file

@ -367,8 +367,10 @@ _spack_get_alias() {
# If all commands in COMPREPLY alias to the same thing, set COMPREPLY to # If all commands in COMPREPLY alias to the same thing, set COMPREPLY to
# just the real command, not the aliases. # just the real command, not the aliases.
_spack_compress_aliases() { _spack_compress_aliases() {
# if there's only one thing, don't bother compressing aliases; complete the alias # If there are zero or one completions, don't do anything
if [ "${#COMPREPLY[@]}" == "1" ]; then # 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 return
fi fi

View file

@ -67,6 +67,9 @@ contains 'concretise' _spack_completions spack c
contains 'concretize' _spack_completions spack conc contains 'concretize' _spack_completions spack conc
does_not_contain 'concretise' _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? # XFAIL: Fails for Python 2.6 because pkg_resources not found?
#contains 'compilers.py' _spack_completions spack unit-test '' #contains 'compilers.py' _spack_completions spack unit-test ''

View file

@ -367,8 +367,10 @@ _spack_get_alias() {
# If all commands in COMPREPLY alias to the same thing, set COMPREPLY to # If all commands in COMPREPLY alias to the same thing, set COMPREPLY to
# just the real command, not the aliases. # just the real command, not the aliases.
_spack_compress_aliases() { _spack_compress_aliases() {
# if there's only one thing, don't bother compressing aliases; complete the alias # If there are zero or one completions, don't do anything
if [ "${#COMPREPLY[@]}" == "1" ]; then # 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 return
fi fi