From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-return-43713-ml=inbox.vuxu.org@zsh.org X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 3ffa1f69 for ; Thu, 18 Oct 2018 21:22:47 +0000 (UTC) Received: (qmail 18189 invoked by alias); 18 Oct 2018 21:22:32 -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: List-Unsubscribe: X-Seq: 43713 Received: (qmail 19785 invoked by uid 1010); 18 Oct 2018 21:22:31 -0000 X-Qmail-Scanner-Diagnostics: from mail-it1-f193.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.166.193):SA:0(-1.9/5.0):. Processed in 2.796711 secs); 18 Oct 2018 21:22:31 -0000 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=from:content-transfer-encoding:mime-version:subject:message-id:date :to; bh=J7ktCyy9cCpKD2IX2kk9dw5uHqbkoG3eZNP+AHULDZc=; b=gVK1oPiAkmUzWBHThN4fNVNIF30G/KZUyYniQ7y8pKyGIgDG/7xWWz/OAOtXHvIVeE v9EtqUmxj0idiUcko5lnQZoGfywb0heetocnCOI3RMG/+9lgyQcVIpERjzcIm0QdSLMY u1hNeliSzKWlKxGPHtIrPedOaJ0m5rIga1AcfH6KHdLLwzf9yrwnSgDBG12+EclWMyNp hlAhtYDLp+k9MVYTFQdpeG8XwyT09hOZ/n7o+EVIYv8Ic8ZzSk98U6bRAlOdntNZz94P sf3JHH3spfTP+foW255tcHvf/k4406SzBh/PM4cr+DzPnXh8g+jhY9mQgsWguu4zONRP TiRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:message-id:date:to; bh=J7ktCyy9cCpKD2IX2kk9dw5uHqbkoG3eZNP+AHULDZc=; b=d+GNl6C0Qk4Od5ngxqd75Y0jrrHHRs3xmZK+rh3FNHOVkW4CyqK+WO2+bZCbJp8PKE 2QVP5fHMJto/FSMTjiCfmecEuzr3+KN0tB9e4V4ScRRBufvMz/Q39PQE5gtV7M0nJ4R9 lH/qvFuAdAcdux7u9fbvlgN8+9SbMpMtMXZ8YIBZntarKjsddUKX/BCKA0T67Dq8MX7b TiJH46ZG1rTE9dB1CZ5HbyJlHce1OsPzVA8Aljh8sohk4+txyZ6QZcxZcatPrX5NEdq+ HLYPjbkJvVISAvbfqhvUe4aphgNG31lDQpkfJ/aNiy3Sh8Sl7G6Yr5nMSgk2AjJcwtXO 17+g== X-Gm-Message-State: ABuFfohuGjzAdQWBtLxBqBZjP46bxI4Zk0oWLADn83LhJ86McaJGLgeZ 27jMn23lSAe4W8jvPoyGzUAgGGWfPZc= X-Google-Smtp-Source: ACcGV63YZr7oQB+Q9GgCMhDbEJKnUv5VuBWkJKuUVG6/R8QNCoOci0+/RfaTMwj+uVqhLcB1cgzxwA== X-Received: by 2002:a24:75d6:: with SMTP id y205-v6mr1569374itc.1.1539897745722; Thu, 18 Oct 2018 14:22:25 -0700 (PDT) From: dana Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: [PATCH] Completion: Improve _init_d command matching Message-Id: <8955857F-C821-4490-8C8D-E2FA633633BB@dana.is> Date: Thu, 18 Oct 2018 16:22:22 -0500 To: Zsh hackers list X-Mailer: Apple Mail (2.3445.9.1) Someone on IRC complained that they weren't getting all of the expected = commands when tab-completing `service apache2`. That's because _init_d won't = match any case clause containing a pattern that wasn't explicitly enumerated, and = the apache2 script had a bunch of those. I updated the script to enumerate several more patterns that i found in = the init scripts on my Ubuntu machine and to make it match quoted patterns = better. (I've never seen a quoted pattern in any of these scripts, but someone once = upon a time apparently thought it was a good idea, so why not.) I also broke up = some of the code into (IMO) more readable chunks, so that hopefully the next = person who has to update this doesn't need to spend as much time on it as i did. dana diff --git a/Completion/Unix/Command/_init_d = b/Completion/Unix/Command/_init_d index 03af2dc9b..cdc373297 100644 --- a/Completion/Unix/Command/_init_d +++ b/Completion/Unix/Command/_init_d @@ -80,15 +80,29 @@ else (( $+functions[_init_d_get_cmds] )) || _init_d_get_cmds() { local what magic cmds + local -a tmp =20 - # If the file starts with `#!' we hope that this is a shell script - # and get lines looking like foo|bar) with the words in = $what. + [[ -x $script ]] || return 1 =20 - = what=3D'(st(art|op|atus)|(force-|)re(start|load)|debug_(up|down)|dump(|_st= ats)|add|delete|clean|list)' + # If the file starts with `#!' we hope that this is a shell script + # and get lines looking like foo|bar) with the words in = $what. Note + # that we'll fail to match if any of the alternate patterns in the = case + # clause are not enumerated (e.g., `start|stop|custom)` won't = match) + tmp=3D( + status add delete clean list + load save show check {config,}test + standalone master graceful + debug debug{_,-}{up,down} dump{,{_,-}stats} + {force-,graceful-,try-,}{start,stop,restart,reload} + {start,stop}-htcacheclean + ) + what=3D"((['\"]|)(${(j<|>)tmp})(['\"]|))" =20 - [[ -x $script ]] || return 1 - read -u0 -k2 magic < $script && [[ $magic =3D '#!' ]] && - cmds=3D( ${${(j:|:s:|:)${(M)${(f)"$(< = $script)"}:#[[:blank:]]#(\'|)${~what}([[:blank:]]#\|[[:blank:]]#${~what})#= (\'|)\)}}//[^-a-z_]} ) + read -u0 -k2 magic < $script && [[ $magic =3D '#!' ]] && { + cmds=3D( ${(f)"$(< $script)"} ) + cmds=3D( = ${(M)cmds:#[[:blank:]]#${~what}([[:blank:]]#\|[[:blank:]]#${~what})#[[:bla= nk:]]#\)} ) + cmds=3D( ${${(j:|:s:|:)cmds}//[^-a-z_]} ) + } =20 # This would be the pattern to use every line of the form = foo). # Some people say this might match too many lines...