From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: (qmail 28377 invoked from network); 26 Mar 2020 00:54:17 -0000 Received-SPF: pass (primenet.com.au: domain of zsh.org designates 203.24.36.2 as permitted sender) receiver=inbox.vuxu.org; client-ip=203.24.36.2 envelope-from= Received: from unknown (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTP; 26 Mar 2020 00:54:17 -0000 Received: (qmail 971 invoked by alias); 26 Mar 2020 00:54:10 -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: 45622 Received: (qmail 5560 invoked by uid 1010); 26 Mar 2020 00:54:10 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25758. spamassassin: 3.4.2. Clear:RC:0(66.111.4.29):SA:0(-2.6/5.0):. Processed in 0.728388 secs); 26 Mar 2020 00:54:10 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehhedgvdehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgogfeguddtqddvjeculdegtddmnecujfgurhephf fvufffkffogggtgfesthektddtredtjeenucfhrhhomhepffgrnhhivghlucfuhhgrhhgr fhcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvgeqnecukfhppeejledrud ejiedruddvhedrvdefvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: From: Daniel Shahaf To: zsh-workers@zsh.org Subject: [PATCH 1/2] _quilt: Categorize subcommands Date: Thu, 26 Mar 2020 00:53:30 +0000 Message-Id: <20200326005331.17708-1-danielsh@tarpaulin.shahaf.local2> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- This is a useful pattern; there's a ton of commands that use it (git, zfs, virsh, systemctl…). It'd be nice to factor it out into a generally-reusable helper function… Cheers, Daniel Completion/Unix/Command/_quilt | 41 ++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/Completion/Unix/Command/_quilt b/Completion/Unix/Command/_quilt index 76dda222f..d086da715 100644 --- a/Completion/Unix/Command/_quilt +++ b/Completion/Unix/Command/_quilt @@ -6,6 +6,8 @@ local verbose='(-h)-v[verbose, more user friendly output]' local color='(-h)--color=[use syntax coloring]:color:(always auto never)' local pstyle='(-h)-p+[select patch style]:patch style:((0\:exclude\ top-level\ directory 1\:use\ .orig\ on\ top-level\ directory ab\:use\ a\ or\ b\ as\ top-level\ directory))' local -a pform rcfile +local k + pform=( '(-U -c -C -h)-u[create a unified diff]' '(-u -c -C -h)-U+[create a unified diff with num lines of context]:lines' @@ -36,12 +38,43 @@ _arguments $help \ '--trace[run the command in bash trace mode]' \ '--quiltrc=[use the specified configuration file]:files:_files' \ '--version[print the version number and exit]' \ - ':quilt command:(add annotate applied delete diff edit files fold fork graph - grep header import mail new next patches pop previous push refresh remove - rename revert series setup snapshot top unapplied upgrade)' \ + ':quilt command:->cmd' \ '*:: :->subcmd' && return -[[ -z $state ]] && return 1 +case $state in + ('') + return 1 + ;; + + (cmd) + # Divide the subcommands to categories. The categorization is our own; + # it's not based on any preexisting categorization in the quilt docs. + local -a manip=( add delete edit fold fork import new refresh remove rename ) + local -a tree=( pop push revert ) + local -a other=( grep header mail setup snapshot upgrade ) + local -a interrogate=( annotate applied diff files graph next patches previous series top unapplied ) + local -A cmdtypes=( + [manip]='series manipulator commands' + [tree]='tree manipulator commands' + [other]='other commands' + [interrogate]='series interrogator commands' + ) + local -a expl=( ) + local ret=1 + _tags ${cmdtypes// /-} + while _tags; do + for k in ${(ok)cmdtypes}; do + _requested ${cmdtypes[$k]// /-} expl ${cmdtypes[$k]} \ + compadd -a - $k && ret=0 + done + done + return ret + ;; + + (subcmd) + ;; +esac + rcfile=( ${opt_args[--quiltrc]:+--quiltrc=${opt_args[--quiltrc]}} ) case $words[1] in add)