From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Paul Seyfert <pseyfert@mathphys.fsk.uni-heidelberg.de>
Cc: zsh-workers@zsh.org
Subject: Re: PATCH Completion for _yum (contains FIXMEs)
Date: Thu, 10 Nov 2016 16:49:26 +0100 [thread overview]
Message-ID: <98208.1478792966@hydra.kiddle.eu> (raw)
In-Reply-To: <d744fcae-f4ad-94b9-04b8-e3c6172ea93c@mathphys.fsk.uni-heidelberg.de>
Paul Seyfert wrote:
>
> Now done as you suggest. Nice indeed (and I learned what the first
> packages in 'packages:packages:...' is good for).
The normal convention is for the descriptions to be in singular form. So
that would be 'packages:package:...'
Thanks for the update. I've got a few comments to add to what Daniel
already said.
+ "repolist:Display the configured software repositories"
+ "distribution-synchronization:Synchronize installed packages to the latest available versions"
+ "distro-sync:Synchronize installed packages to the latest available versions"
Another convention is lowercase for the descriptions, so "display",
"synchronize", etc.
+# Expand next argument after 'yum check'
+_yum_check() {
+ if (( CURRENT == 2 )); then
+ local -a chkargs
+ #chkargs=("dependencies" "duplicates" "obsoletes" "provides" "all") # according to man page
+ #chkargs=("dependencies" "duplicates" "all") # according to help
+ chkargs=("dependencies" "duplicates" "provides" "all") # what works for me
+ _describe -t arguments 'check arguments' chkargs
In quite a few cases, you're using _describe to add matches without
per-match descriptions. The whole point of _describe is to make it easy
to add matches that do have per-match descriptions. For this, you can
just use _wanted with compadd which is much more light-weight:
local expl
_wanted arguments expl 'check argument' compadd dependencies \
duplicates provides all
+ return 0
Completion functions should only return 0 if they added matches.
Otherwise, completion goes on and tries approximate completion and other
fallbacks you may have configured. Often you don't need a return
statement because if the last command is _wanted or _describe then its
return status will be passed on. In complex cases, start with local
ret=1, put && ret=0 after all commands that may add matches and finish
the function with return ret.
+_ids() {
It's probably unwise to define yum specific functions with generic names
like _ids and _ranges. A common convention would be _yum_ids with
_yum-check being for completion after "yum check".
+ # the last argument will be the first valid transaction ID to be suggested
+ # all other arguments are forwarded to compadd
+ #
+ # maxid is the last transaction ID known to yum
+ # minusone is the number of arguments provided to _ids minus one
+ local maxid
+ local minusone
+
+ maxid=$(yum history stats | grep Transactions | sed "s/.*: //")
+ ((minusone=$#-1))
+ compadd "${(@)@[1,$minusone]}" $(echo {$@[$#]..$maxid})
I'm getting some stderr output from yum history stats in my terminal
from this. I don't think you need the echo inside a subshell, the
brace-expansion alone should work.
+# Expand next argument after 'yum history'
+_yum_history() {
+ if (( CURRENT == 2 )); then
+ local -a historycommands
+ historycommands=('info' 'list' 'packages-list' 'packages-info' 'summary' 'addon-info' 'redo' 'undo' 'roll-back' 'new' 'sync' 'stats')
+ _describe -t commands 'yum history command' historycommands
+ fi
+ if (( CURRENT == 3 )); then
A minor point, but you can use elif here.
+ (( ${+alts[1]} )) && _alternative "$alts[@]" || \
+ _message "unknown expansion for: yum history $words[2]"
This will print the message in the case where _alternative is run but
there were no matches which I don't think is what you want. A full
if…then…else should be used.
And rather than printing a message, I think it is best to call _default
as the fallback so that the user gets filename completion. In the case
of a new subcommand being added in a new version of yum falling back to
default completion is more graceful.
Oliver
next prev parent reply other threads:[~2016-11-10 15:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-26 17:37 Paul Seyfert
2016-10-27 1:30 ` Daniel Shahaf
2016-10-31 12:09 ` Paul Seyfert
2016-11-10 10:18 ` Paul Seyfert
2016-11-10 15:49 ` Oliver Kiddle [this message]
2016-11-12 0:19 ` PATCH Completion for _yum Paul Seyfert
[not found] ` <31607.1478915523@hydra.kiddle.eu>
2016-11-22 19:05 ` caching mechanism and " Oliver Kiddle
2016-12-13 10:10 ` Oliver Kiddle
2016-12-13 16:18 ` Jun T.
2016-12-13 17:21 ` Bart Schaefer
2016-12-14 11:38 ` Oliver Kiddle
2016-12-14 14:23 ` Jun T.
2016-12-14 15:03 ` Oliver Kiddle
2016-12-14 15:23 ` Jun T.
2016-12-14 17:46 ` Oliver Kiddle
2016-12-14 20:09 ` Bart Schaefer
2016-12-15 9:38 ` Peter Stephenson
2016-12-15 17:15 ` Before 5.3.1 (was Re: caching mechanism and Re: PATCH Completion for _yum) Bart Schaefer
2016-12-13 16:38 ` caching mechanism and Re: PATCH Completion for _yum Bart Schaefer
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=98208.1478792966@hydra.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=pseyfert@mathphys.fsk.uni-heidelberg.de \
--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).