From b0be6f4b63a078151c8462bb5466d7b13c347e68 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sun, 2 Oct 2022 11:19:37 +0200 Subject: [PATCH] zsh: improve reuse completion --- .config/zsh/completions/_reuse | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.config/zsh/completions/_reuse b/.config/zsh/completions/_reuse index 21f43f3..cd1cba8 100644 --- a/.config/zsh/completions/_reuse +++ b/.config/zsh/completions/_reuse @@ -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)