options_by_key = {o.short: o for o in options if o.short} | {o.long: o for o in options if o.long}
with io.StringIO() as c:
- c.write("# SPDX-License-Identifier: LGPL-2.1-or-later\n\n")
+ c.write(completion.read_text())
+
c.write(to_bash_array("_mkosi_options", options_by_key.keys()))
c.write("\n\n")
c.write(to_bash_array("_mkosi_verbs", [str(v) for v in config.Verb]))
c.write("\n\n\n")
- c.write(completion.read_text())
-
return c.getvalue()
completion = resources / "completion.zsh"
with io.StringIO() as c:
- c.write("#compdef mkosi\n")
- c.write("# SPDX-License-Identifier: LGPL-2.1-or-later\n\n")
+ c.write(completion.read_text())
+ c.write("\n")
c.write(to_zsh_array("_mkosi_verbs", [str(v) for v in config.Verb]))
c.write("\n\n")
- c.write(completion.read_text())
- c.write("\n")
-
c.write("_arguments -s \\\n")
c.write(" '(- *)'{-h,--help}'[Show this help]' \\\n")
c.write(" '(- *)--version[Show package version]' \\\n")
+# SPDX-License-Identifier: LGPL-2.1-or-later
+# shellcheck shell=bash
+
_mkosi_compgen_files() {
compgen -f -- "$1"
}
}
_mkosi_completion() {
- local completing_program="$1"
+ # completing_program="$1"
local completing_word="$2"
local completing_word_preceding="$3"
if [[ "$completing_word" =~ ^- ]] # completing an option
then
- COMPREPLY=( $(compgen -W "${_mkosi_options[*]}" -- "${completing_word}") )
+ readarray -t COMPREPLY < <(compgen -W "${_mkosi_options[*]}" -- "${completing_word}")
elif [[ "$completing_word_preceding" =~ ^- ]] # the previous word was an option
then
if [[ -n "${current_option_compgen}" ]]
then
- local IFS=$'\n'
- COMPREPLY=( $("${current_option_compgen}" "${completing_word}") )
- unset IFS
+ readarray -t COMPREPLY < <("${current_option_compgen}" "${completing_word}")
fi
- COMPREPLY+=( $(compgen -W "${current_option_choices}" -- "${completing_word}") )
+ readarray -t COMPREPLY -O "${#COMPREPLY[@]}" \
+ < <(compgen -W "${current_option_choices}" -- "${completing_word}")
if [[ "${current_option_nargs}" == "?" ]]
then
- COMPREPLY+=( $(compgen -W "${_mkosi_verbs[*]}" -- "${completing_word}") )
+ readarray -t COMPREPLY -O "${#COMPREPLY[@]}" \
+ < <(compgen -W "${_mkosi_verbs[*]}" -- "${completing_word}")
fi
else
# the preceding word wasn't an option, so we are doing position
# arguments now and all of them are verbs
- COMPREPLY=( $(compgen -W "${_mkosi_verbs[*]}" -- "${completing_word}") )
+ readarray -t COMPREPLY < <(compgen -W "${_mkosi_verbs[*]}" -- "${completing_word}")
fi
}