# Print all options of the given optstring to stdout if the word in the current
# command line begins with a hyphen character.
+#
+# Returns 0 if the current word does not start with a hyphen, one otherwise.
gsu_complete_options()
{
local opts="$1" cword="$2" cur opt
ret=0
[[ ! "$cur" == -* ]] && return
- ret=0
for ((i=0; i < ${#opts}; i++)); do
opt="${opts:$i:1}"
[[ "$opt" == ":" ]] && continue
printf "%s" "-$opt "
- let ret++
done
+ ret=1
}
com_prefs_options='e'
local -a candidates;
candidates=(\$($0 complete "\$COMP_CWORD" "\${COMP_WORDS[@]}"));
- COMPREPLY=(\$(compgen -W "\${candidates[*]}" -- "\$cur"));
+ if ((\$? == 0)); then
+ COMPREPLY=(\$(compgen -W "\${candidates[*]}" -- "\$cur"));
+ else
+ compopt -o filenames;
+ COMPREPLY=(\$(compgen -fd -- "\$cur"));
+ fi
EOF
ret=$GSU_SUCCESS
return
shift
words=("$@")
cmd="${words[1]}"
- ret=$GSU_SUCCESS # It's not an error if no completer was defined
- [[ "$(type -t "complete_$cmd")" != "function" ]] && return
+ # if no completer is defined for this subcommand we exit unsuccessfully
+ # to let the generic completer above fall back to file name completion.
+ [[ "$(type -t "complete_$cmd")" != "function" ]] && exit 1
"complete_$cmd" "$cword" "${words[@]}"
# ignore errors, they would only clutter the completion output
ret=$GSU_SUCCESS