if [[ $COMP_CWORD -le $cmd_index ]]; then
# The user has not specified a command yet
local all_commands="$(tmux -q list-commands | cut -f 1 -d ' ')"
COMPREPLY=( ${COMPREPLY[@]:-} $(compgen -W "${all_commands}" -- "${cur}") )
I am trying to understand above code snippet for tmux bash autocompletion
compgen's W argument takes a word-list. But why does it taken an extra option --
with the current word, ${cur}
as argument?
What does :-
inside flower brackets mean?${COMPREPLY[@]:-}
When i do, tmux<tab>
the completion list displayed is same as $(tmux -q list-commands | cut -f 1 -d ' ')
.
So, why do we need ${COMPREPLY[@]:-}
in the array beginning?
:-}
smiley looks awesome? Joke aside, the--
likely is there to make it known that the next argument is not an option! My guess would be that Bash usesgetopt
internally, so it relies on these conventions?! – 0xC0000022L Jul 27 '15 at 15:31:-
is meant to remove the empty strings from inside the array.... So, need to understand what does double hypen mean as an argument to compgen... – Jul 27 '15 at 17:21