zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <oliver@kiddle.eu>
To: Zsh workers <zsh-workers@zsh.org>
Subject: using tag-order with _pids
Date: Tue, 22 Jul 2014 12:31:38 +0200	[thread overview]
Message-ID: <18723.1406025098@thecus.kiddle.eu> (raw)

The patch below moves the use of _call_program by _pids to inside the
_tags loop. Much of the patch is just reindentation. The purpose of this
is to allow separate processes to be grouped so _next_tags can expand
the list to include a wider range of processes. So for example:

  zstyle ':completion:*:kill:*:' tag-order processes:-tty \
      'processes:-mine:user\ processes' 'processes:-all:all\ processes'
  zstyle ':completion:*:processes-mine' command 'ps -u $EUID'
  zstyle ':completion:*:processes-all' command 'ps -e'

There are some things that aren't ideal about this: the tag-order style
has to be defined for e.g. the kill command and can't apply whenever
_pids is called. Also an ambiguous prefix from the first tag limits
matches in later tags. If anyone has any ideas on solutions to these
issues, I'd be interested to know.

Oliver

diff --git a/Completion/Unix/Type/_pids b/Completion/Unix/Type/_pids
index 3f99dfd..3c6a765 100644
--- a/Completion/Unix/Type/_pids
+++ b/Completion/Unix/Type/_pids
@@ -20,25 +20,30 @@ else
   nm="$compstate[nmatches]"
 fi
 
-out=( "${(@f)$(_call_program processes ps 2>/dev/null)}" )
-desc="$out[1]"
-out=( "${(@M)out[2,-1]:#${~match}}" )
-
-if [[ "$desc" = (#i)(|*[[:blank:]])pid(|[[:blank:]]*) ]]; then
-  pids=( "${(@)${(@M)out#${(l.${#desc[1,(r)(#i)[[:blank:]]pid]}..?.)~:-}[^[:blank:]]#}##*[[:blank:]]}" )
-else
-  pids=( "${(@)${(@M)out##[^0-9]#[0-9]#}##*[[:blank:]]}" )
-fi
-
-if zstyle -T ":completion:${curcontext}:processes" verbose; then
-  list=( "${(@Mr:COLUMNS-1:)out}" )
-  desc=(-ld list)
-else
-  desc=()
-fi
-
-_wanted -V processes expl 'process ID' \
-    compadd "$@" "$desc[@]" "$all[@]" -a - pids && ret=0
+while _tags; do
+  if _requested processes; then
+    while _next_label processes expl 'process ID'; do
+      out=( "${(@f)$(_call_program $curtag ps 2>/dev/null)}" )
+      desc="$out[1]"
+      out=( "${(@M)out[2,-1]:#${~match}}" )
+
+      if [[ "$desc" = (#i)(|*[[:blank:]])pid(|[[:blank:]]*) ]]; then
+	pids=( "${(@)${(@M)out#${(l.${#desc[1,(r)(#i)[[:blank:]]pid]}..?.)~:-}[^[:blank:]]#}##*[[:blank:]]}" )
+      else
+	pids=( "${(@)${(@M)out##[^0-9]#[0-9]#}##*[[:blank:]]}" )
+      fi
+
+      if zstyle -T ":completion:${curcontext}:$curtag" verbose; then
+	list=( "${(@Mr:COLUMNS-1:)out}" )
+	desc=(-ld list)
+      else
+	desc=()
+      fi
+      compadd "$@" "$expl[@]" "$desc[@]" "$all[@]" -a pids && ret=0
+    done
+  fi
+  (( ret )) || break
+done
 
 if [[ -n "$all" ]]; then
   zstyle -s ":completion:${curcontext}:processes" insert-ids out || out=menu


             reply	other threads:[~2014-07-22 10:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-22 10:31 Oliver Kiddle [this message]
2014-07-23  3:58 ` Bart Schaefer
2014-07-31 16:30   ` Oliver Kiddle
2014-08-04 17:47     ` 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=18723.1406025098@thecus.kiddle.eu \
    --to=oliver@kiddle.eu \
    --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).