Skip to content

Commit 26052eb

Browse files
authored
Merge pull request #2293 from convergedtarkus/improveAliasCompletion
Improve array handling in alias completion
2 parents 43285e7 + 3e9a033 commit 26052eb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

completion/available/aliases.completion.bash

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ function _bash-it-component-completion-callback-on-init-aliases() {
7878
# avoid recursive call loops by ignoring our own functions
7979
if [[ "${compl_func#_"$namespace"::}" == "$compl_func" ]]; then
8080
compl_wrapper="_${namespace}::${alias_name}"
81+
82+
# Create a wrapper function for the alias
83+
# The use of printf on alias_arg_words is needed to ensure each element of
84+
# the array is quoted. E.X. (one two three) -> ('one' 'two' 'three')
8185
echo "function $compl_wrapper {
8286
local compl_word=\${2?}
8387
local prec_word=\${3?}
@@ -89,7 +93,7 @@ function _bash-it-component-completion-callback-on-init-aliases() {
8993
prec_word=\${prec_word#* }
9094
fi
9195
(( COMP_CWORD += ${#alias_arg_words[@]} ))
92-
COMP_WORDS=(\"$alias_cmd\" \"${alias_arg_words[*]}\" \"\${COMP_WORDS[@]:1}\")
96+
COMP_WORDS=(\"$alias_cmd\" $(printf "%q " "${alias_arg_words[@]}") \"\${COMP_WORDS[@]:1}\")
9397
(( COMP_POINT -= \${#COMP_LINE} ))
9498
COMP_LINE=\${COMP_LINE/$alias_name/$alias_cmd $alias_args}
9599
(( COMP_POINT += \${#COMP_LINE} ))

0 commit comments

Comments
 (0)