zsh: improve reuse completion

This commit is contained in:
tastytea 2022-10-02 11:19:37 +02:00
parent f691b2129c
commit b0be6f4b63
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM

View File

@ -7,10 +7,19 @@
local curcontext=${curcontext} state state_descr line ret=1
function _reuse_licenses() {
local licenses=(
$(reuse supported-licenses 2>&- | cut -d' ' -f1)
)
_values 'license' ${licenses}
local -a licenses
OLDIFS=${IFS}
IFS=$'\n'
for line in $(reuse supported-licenses 2>&-); do
# remove everything before and including the first whitespace and
# everything after and including the first http
desc=${${line#*[[:blank:]]}%[[:blank:]]http*}
# trim whitespace
[[ ${desc} =~ '^\s*(\S.*\S)\s*$' ]] && desc=$match[1] || desc=''
licenses+=(${line%% *}:${desc})
done
IFS=${OLDIFS}
_describe -t licenses license licenses && ret=0
}
function _reuse_styles() {
@ -71,10 +80,8 @@ case ${state} in
init:'initialize REUSE project'
lint:'list all non-compliant files'
spdx:"print the project's bill of materials in SPDX format"
supported-licenses:'list all supported SPDX licenses'
supported-licences:'list all supported SPDX licences'
{supported-licenses,supported-licences}:'list all supported SPDX licenses'
)
_describe -t subcommands subcommand subcommands && ret=0
;;
(subcommand)
@ -87,7 +94,7 @@ case ${state} in
{'(--license)-l','(-l)--license'}'[SPDX Identifier, repeatable]':license:_reuse_licenses \
{'(--year)-y','(-y)--year'}'[year of copyright statement, optional]':year \
{'(--style)-s','(-s)--style'}'[comment style to use, optional]':style:_reuse_styles \
--copyright-style'[copyright style to use, optional]':copyright\ style:_reuse_copyright_styles \
--copyright-style'[copyright style to use, optional]':'copyright style':_reuse_copyright_styles \
{'(--template)-t','(-t)--template'}'[name of template to use, optional]':template \
--exclude-year'[do not include year in statement]' \
--merge-copyrights'[merge copyright lines if copyright statements are identical]' \
@ -97,6 +104,7 @@ case ${state} in
{'(--recursive)-r','(-r)--recursive'}'[add headers to all files under specified directories recursively]' \
--skip-unrecognised'[skip files with unrecognised comment styles]' \
--skip-existing'[skip files that already contain SPDX information]' \
1:path:'_files' \
&& ret=0
;;
(download)