From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28516 invoked by alias); 7 Oct 2014 13:20:36 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33375 Received: (qmail 3848 invoked from network); 7 Oct 2014 13:20:24 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=0C7DdIWHXdkK1KuQAusOIXeGl0jD3ZGAlMJ+k/Su9mc=; b=FSm3vrvtrNw7Z9ddRSS9PqQDggFlM9r7kfrI97JIazWGNTz3xZVMEOt5zjFiAnguW2 Rp+JB+sIitlxfgM7nCSzXkpZbqBlOZi/zQRzXwvsCjCEBWwg+YTr3QywLxV9IA0Kqafo chkQH+T8tStj5rwKlRutooF1x97mQ97Sc/k+V7G2p7dFWLKvugyScb7E/RFs8EM/NF+E Ybjrhuxl6jGHj+EjX0Np7soARbyGiAH5qRNU+qmqTfxhCOMqF2o517bi3b/gRjrFH22/ 9hgZLFi9ZZ0pnWdNJX+LZDLi3WqH8gnlULbLRZdQdXAw8qav3nvf9BYOGF0MeF0KbDyf ewJw== X-Received: by 10.60.37.9 with SMTP id u9mr4044895oej.18.1412688017485; Tue, 07 Oct 2014 06:20:17 -0700 (PDT) Date: Tue, 7 Oct 2014 08:20:25 -0500 From: fREW Schmidt To: Oliver Kiddle Cc: zsh-workers@zsh.org Subject: Re: [PATCH] new completion for "sv" Message-ID: <20141007132025.GA6252@gae-bulg.lan.mitsi.com> References: <20141005200135.GD58824@wanderlust.lan.mitsi.com> <5624.1412624240@quattro> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="MW5yreqqjyrRcusr" Content-Disposition: inline In-Reply-To: <5624.1412624240@quattro> User-Agent: Mutt/1.5.22.1 (2013-10-16) --MW5yreqqjyrRcusr Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz" Content-Disposition: inline --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 06, 2014 at 09:37:20PM +0200, Oliver Kiddle wrote: > fREW Schmidt wrote: > >=20 > > If anything is wrong just let me know, this would be my first > > contribution to zsh so mistakes wouldn't surprise me. >=20 > I've got a few comments. >=20 > > +#compdef sv > > + > > +_arguments \ > > + '-v[verbose]' \ > > + '-w:wait time' \ >=20 > What's the units for the time? How about something like: > '-w[specify wait time]:time (seconds)' Good idea > > + ':command:->command' \ > > + '*::options:->options' >=20 > If you use states with _arguments, you should declare a few array > variables local: context, state and line. You then need to take care to > make use of the context variable when calling other functions. In most > cases, including the one above, only one state is possible at a time. So > in this case, you should declare: > local curcontext=3D"$curcontext" state line > and pass the -C option to _arguments. Ok, I think I did this right this time. > > + sv_ary=3D( > > + 'status':'Get status of service (and log service if availab= le)' >=20 > The usual convention, which you have done elsewhere, is to start > descriptions with a lowercase letter. Woops! Fixed. > > + _describe -t commands "sv commands" sv_ary -V sv_commands > > + _describe -t commands "sv LSM init compat" sv_lsb_ary -V sv_init= _compat > > + _describe -t commands "sv additional commands" '("check:check st= atus of service")' -V sv_addl_comm > > + return >=20 > This is ignoring the return status of the first two calls to _describe. > The return value of a completion function determines whether the > completion system carries on trying to find more matches, perhaps > approximate matching if you have that configured. It's common to use a > variable named ret for the return status: look for some examples. >=20 > Perhaps also consider using three different tags for the matches and using > _alternative or _tags with a loop. ok, I switched it to use _alternative and 3 functions as seems to be somewhat common in other compltion scripts in the codebase. > > + $SVDIR/*(N) >=20 > Is SVDIR really always set or is there a default value that it could > fall back on, e.g: ${SVDIR:-/service} This raises an interesting question. I did what you said, but as Christian Neukirchen pointed out, on his system the default SVDIR is /var/service, and on ubuntu the default is /etc/service. I guess it's up to the packager to tweak the script or something? Additionally, I like Christian Neukirchen's single-character shortcut completion. For majority of the commands they work already since nothing else starts with that letter, but s and c both have multiple options. If I understood what I was doing more I'd take his idea, but I don't. Anyway, see a new version attached. Let me know what else is (still?) wrong. Thanks! (Again, please CC me in responses.) --=20 fREW Schmidt https://blog.afoolishmanifesto.com --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-new-completion-for-sv.patch" Content-Transfer-Encoding: quoted-printable =46rom 05f0fab3a7ddc666c8c0b89fd48b8c05f41b7b52 Mon Sep 17 00:00:00 2001 =46rom: Arthur Axel 'fREW' Schmidt Date: Sun, 5 Oct 2014 14:52:42 -0500 Subject: [PATCH] new completion for "sv" See http://smarden.org/runit/sv.8.html --- Completion/Unix/Command/_sv | 73 +++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 73 insertions(+) create mode 100644 Completion/Unix/Command/_sv diff --git a/Completion/Unix/Command/_sv b/Completion/Unix/Command/_sv new file mode 100644 index 0000000..b2fedc5 --- /dev/null +++ b/Completion/Unix/Command/_sv @@ -0,0 +1,73 @@ +#compdef sv + +_sv_commands() { + local -a sv_ary + sv_ary=3D( + 'status':'get status of service (and log service if available)' + 'up':'start if service is running. If service stops, restart' + 'down':'send SIGTERM and SIGCONT if service is running. After = it stops, do not restart' + 'once':'start if service is not running. Do not restart if it = stops' + 'pause':'send SIGSTOP if service is running' + 'cont':'send SIGCONT if service is running' + 'hup':'send SIGHUP if service is running' + 'alarm':'send SIGALRM if service is running' + 'interrupt':'send SIGINT if service is running' + 'quit':'send SIGQUIT if service is running' + '1':'send SIGUSR1 if service is running' + '2':'send SIGUSR2 if service is running' + 'term':'send SIGTERM if service is running' + 'kill':'send SIGKILL if service is running' + 'exit':'send SIGTERM and SIGCONT if service is running. Do not= restart service.' + ) + _describe -t commands "sv commands" sv_ary -V sv_commands +} + +_sv_lsb() { + local -a sv_lsb_ary + sv_lsb_ary=3D( + 'start':'up with check/timeout' + 'stop':'down with check/timeout' + 'reload':'hup with check' + 'restart':'down and up with check' + 'shutdown':'exit with check/timeout' + 'force-stop':'stop with kill on timeout' + 'force-reload':'reload with kill on timeout' + 'force-restart':'restart with kill on timeout' + 'force-shutdown':'shutdown with kill on timeout' + 'try-restart':'restart if service is already running' + ) + + _describe -t lsb-commands "sv LSM init compat" sv_lsb_ary -V sv_init_c= ompat +} + +_sv_additional() { + _describe -t additional-commands "sv additional commands" '("check:che= ck status of service")' -V sv_addl_comm +} + +local curcontext=3D"$curcontext" state line +_arguments -C \ + '-v[verbose]' \ + '-w[wait time]:time (seconds)' \ + '1: :->command' \ + '*:: :->options' + +case $state in + (command) + _alternative \ + _sv_commands \ + _sv_lsb \ + _sv_additional + ;; + + (options) + local -a sv_services + local svdir=3D${SVDIR:-/service} + sv_services=3D( + $svdir/*(N) + $svdir/*/log(N) + ) + + sv_services=3D( ${sv_services#$svdir/} ) + _describe -t services "sv services" sv_services + ;; +esac --=20 2.0.0.390.gcb682f8 --3V7upXqbjpZ4EhLz-- --MW5yreqqjyrRcusr Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAABCgAGBQJUM+iXAAoJEG6zMC9zenWCWvkP/i7rF7FmDWunApvQU+qwp6RO S0Uuwo56rDSMaNVmLO7Izqauq1qj2B72e/eEH0IF00vWPm2rp9FxT3LYepAxh9WT pAgRxOUUmKisNFFlEl6jDp8oqld5bGMEAdCH76+X3YRyXHwUMHOqJG27/FPvh9id 9m5ZNp9ImufmkchNAiSnCEW7PuJuFgFVgYZF17zMTDK/a0Lx+4KgQSOfSfZl4bkB GNccbqZHW0VINHW5eR4tWiz2TcdSO9JLzCThmocfbEaWN7wYgB9M9hRGE60/kgi5 vSo4whSNujLdORahyzmdQO7SGfAg3YhS+Mt7+sEaKL9nRdhMT++19mjFJAR/ztdc b/SsaUN4mKQsODbHN01WhkxiSiK+yTbeti5I20VeZlRDZvoTh8uh0vsclpg8NYHL FmSpE5qHBC0d0GYG8d+QySyc34OwPaoxT7MTUh4Re/gMEf67As0zJ6JjSuflOwc1 fOsxsBGWrlfYzX4fmJ9L1bFaJGAJpJZdOgNgGRafd8WevfRTtHdLBW5asSvg/5NN U1ionFYBF5k3i+o2o3TYRc4vqnTmfIzEFhLGuXCIQmcyEHbDVbjME6m7wE0rPA9R TEtLYHBWP9no7vwzIKptiYoW6tQSw4RPFk/ICask/mFo39FuQ+70dJcKd5V1nOtw qxlhMb8nSd9WqHL03XwV =0N9A -----END PGP SIGNATURE----- --MW5yreqqjyrRcusr--