From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] _debsnap: New completion function.
Date: Mon, 27 Apr 2020 19:35:18 +0000 [thread overview]
Message-ID: <20200427193518.30e381ac@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20200427113813.1701-1-danielsh@tarpaulin.shahaf.local2>
Daniel Shahaf wrote on Mon, 27 Apr 2020 11:38 +0000:
> ---
> Completion/Debian/Command/_debsnap | 52 ++++++++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
> create mode 100644 Completion/Debian/Command/_debsnap
Revised version. The version numbers are now sorted «dpkg
--compare-versions»-ly rather than alphabetically, and are limited by
--first/--last. No other changes.
Cheers,
Daniel
[[[
#compdef debsnap
# Based on debsnap from devscripts-2.20.3
local context state state_descr line ret=1
local -a expl
typeset -A opt_args
_arguments \
'(-d --destdir)'{-d+,--destdir=}'[set download directory]:download directory:_files -/' \
'(-f --force)'{-f,--force}'[allow non-empty destination directory]' \
'(-v --verbose)'{-v,--verbose}'[print configuration and report progress]' \
--list"[list versions; don't download]" \
--binary'[operate on binary packages (default: source packages)]' \
'*'{-a+,--architecture=}'[specify architectures to download]:architecture to download:_deb_architectures' \
--first='[download all versions newer than this]:version number (lower bound):->versions' \
--last='[download all versions older than this]:version number (upper bound):->versions' \
'(-)'{-h,--help}'[show usage information]' \
'(-)'--version'[show version number and license]' \
'1: :->package' \
'2:version number to download:->versions' \
&& ret=0
# -a implies --binary
if (( ${+opt_args[-a]} || ${+opt_args[--architecture]} )); then
opt_args[--binary]=''
fi
case $state in
(package)
if (( ${+opt_args[--binary]} )); then
_description binary-packages expl 'binary package to download'
_deb_packages "${expl[@]}" avail && ret=0
else
_description source-packages expl 'source package to download'
_deb_packages "${expl[@]}" source && ret=0
fi
;;
(versions)
local package=${(Q)line[1]}
if [[ -n $package ]]; then
# Compute the arguments to --list
local -a args
() {
local i j
# repeatable flags with arguments, where the values can't contain colons
for i in ${(k)opt_args[(I)(-a|--architecture)]}; do
for j in ${(@s.:.)opt_args[$i]}; do
[[ -n $j ]] || continue
args+=( $i $j )
done
done
# non-repeatable flags with arguments, where the values may contain colons
for i in ${(k)opt_args[(I)(--first|--last)]}; do
# Avoid spurious "No matches" results in 'debsnap --first 42.1 --last 42.<TAB>'.
[[ $context != option${i}-* ]] || continue
# Un-escape colons (epoch separators in the version number)
args+=( $i ${(Q)opt_args[$i]} )
done
# flags without arguments
args+=( ${(k)opt_args[(I)(--binary)]} )
}
local -a versions=( ${(Oaf)"$(_call_program versions debsnap --list ${args} -- ${line[1]})"} )
_description -V versions expl ${state_descr}
compadd "$@" "${expl[@]}" -a versions && ret=0
else
_message -- $state_descr && ret=0
fi
;;
esac
return ret
]]]
prev parent reply other threads:[~2020-04-27 19:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-27 11:38 Daniel Shahaf
2020-04-27 19:35 ` Daniel Shahaf [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200427193518.30e381ac@tarpaulin.shahaf.local2 \
--to=d.s@daniel.shahaf.name \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).