zsh-workers
 help / color / Atom feed
* [PATCH 1/2] _quilt: Categorize subcommands
@ 2020-03-26  0:53 Daniel Shahaf
  2020-03-26  0:53 ` [PATCH 2/2] _quilt: Add subcommand descriptions Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2020-03-26  0:53 UTC (permalink / raw)
  To: zsh-workers

---
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)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] _quilt: Add subcommand descriptions
  2020-03-26  0:53 [PATCH 1/2] _quilt: Categorize subcommands Daniel Shahaf
@ 2020-03-26  0:53 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2020-03-26  0:53 UTC (permalink / raw)
  To: zsh-workers

---
The descriptions are adapted from the quilt(1) man page.  I don't think
that raises any copyright concerns; just mentioning this out of an
abundance of caution.

Cheers,

Daniel

 Completion/Unix/Command/_quilt | 50 +++++++++++++++++++++++++++++-----
 1 file changed, 43 insertions(+), 7 deletions(-)

diff --git a/Completion/Unix/Command/_quilt b/Completion/Unix/Command/_quilt
index d086da715..8167bce1e 100644
--- a/Completion/Unix/Command/_quilt
+++ b/Completion/Unix/Command/_quilt
@@ -49,23 +49,59 @@ case $state in
   (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 manip=(
+      add:'add files to a patch'
+      delete:'remove a patch from the series'
+      edit:'add files to the topmost patch and open them in $EDITOR'
+      fold:'integrate an external patch into the topmost patch'
+      fork:'replace the topmost patch with a copy'
+      import:'add external patches to the series'
+      new:'add an empty patch to the series'
+      refresh:'update a patch with in-tree edits'
+      remove:'remove files from a given patch'
+      rename:"change a patch's name"
+    )
+    local -a tree=(
+      pop:'unapply a patch to the tree'
+      push:'apply a patch to the tree'
+      revert:'discard in-tree changes to files in a given patch'
+    )
+    local -a other=(
+      grep:'print file lines matching pattern'
+      header:"print or change a patch's prologue"
+      mail:'send patches by email'
+      setup:'initialize a source tree'
+      snapshot:'save a snapshot of the tree to diff against'
+      upgrade:'upgrade quilt metadata'
+    )
+    local -a interrogate=(
+      annotate:'show which patches modify which lines'
+      applied:'print the list of patches up to a given patch'
+      diff:'print differences between files'
+      files:'print the list of files that a given patch changes'
+      graph:'generate a patches dependency graph'
+      next:'print the name of the patch that follows a given patch'
+      patches:'print the list of patches that touch a given file'
+      previous:'print the name of the patch that precedes a given patch'
+      series:'print the list of all patches'
+      top:'print the name of the last applied patch'
+      unapplied:'print the list of patches following a given patch'
+    )
     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
+        if _requested ${cmdtypes[$k]// /-}
+        then
+          _describe -t ${cmdtypes[$k]// /-} ${cmdtypes[$k]} $k &&
+            ret=0
+        fi
       done
     done
     return ret

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26  0:53 [PATCH 1/2] _quilt: Categorize subcommands Daniel Shahaf
2020-03-26  0:53 ` [PATCH 2/2] _quilt: Add subcommand descriptions Daniel Shahaf

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git