zsh-workers
 help / color / mirror / code / Atom feed
From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: [PATCH] _ttys: complete only active ttys
Date: Thu, 28 Jun 2018 16:39:08 +0900	[thread overview]
Message-ID: <90FE62AE-8433-4C3E-957D-7849153AF375@kba.biglobe.ne.jp> (raw)

Add an option -o to _ttys to complete only those ttys to which processes
are attached. I used a tag name 'open-ttys' for this but not sure if this
is an appropriate name.

Updated _ps and _watch-snoop to use this option.



diff --git a/Completion/BSD/Command/_watch-snoop b/Completion/BSD/Command/_watch-snoop
index 182b6bb34..1a4af07cc 100644
--- a/Completion/BSD/Command/_watch-snoop
+++ b/Completion/BSD/Command/_watch-snoop
@@ -10,4 +10,4 @@ _arguments -w -S -s : \
   "-o[reconnect on overflow]" \
   "-t[print date and time at start]" \
   "-W[allow write access to observed tty]" \
-  ":tty device:_ttys -D"
+  "(-): : _ttys -Do"
diff --git a/Completion/Unix/Command/_ps b/Completion/Unix/Command/_ps
index a8208a365..72e711227 100644
--- a/Completion/Unix/Command/_ps
+++ b/Completion/Unix/Command/_ps
@@ -31,7 +31,7 @@ args=(
   '*-G+[select processes by real group]:group:_sequence -s , _groups'
   '*-g+[select processes by effective group or session]:group:_sequence -s , _groups'
   '*-s+[select processes by session leaders]:session leader:_sequence -s , _pids'
-  '*-t+[select processes by attached terminal]:tty:_sequence -s , _ttys -D'
+  '*-t+[select processes by attached terminal]:tty:_sequence -s , _ttys -Do'
   '*-u+[select processes by effective user]:user:_sequence -s , _users'
   '*-U+[select processes by real user]:user:_sequence -s , _users'
   '-o+[specify output format]:property:_sequence -s , _ps_props -'
@@ -211,7 +211,7 @@ if (( CURRENT > 1 )) && [[ $OSTYPE != (solaris*|linux-gnu) ||
     *J) _sequence _jails -0 && return ;;
     *[MNW]) _files && return ;;
     *t)
-      _wanted -C option-t-1 ttys expl tty _sequence -s , _ttys -D && return
+      _wanted -C option-t-1 ttys expl tty _sequence -s , _ttys -Do && return
     ;;
     *[pq]) _wanted -C "option-${words[CURRENT-1][-1]}-1" processes \
 	expl 'process ID' _sequence -s , _pids && return ;;
diff --git a/Completion/Unix/Type/_ttys b/Completion/Unix/Type/_ttys
index 5e5598570..7408395c8 100644
--- a/Completion/Unix/Type/_ttys
+++ b/Completion/Unix/Type/_ttys
@@ -4,16 +4,22 @@
 #
 # -d  strip /dev/ prefix from matches
 # -D  matches allowed with or without /dev/ prefix
+# -o  only complete those ttys to which processes are attached
 
 local -a ttys expl pre
-local stripdev optdev
+local stripdev optdev open
 
-zparseopts -D -K -E d=stripdev D=optdev
+zparseopts -D -K -E d=stripdev D=optdev o=open
 
-ttys=( /dev/tty?*(N) /dev/pts/^ptmx(N) )
-ttys=( ${ttys#/dev/} )
+if [[ -n $open ]]; then
+  ttys=( ${(u)${(f)"$(_call_program open-ttys ps -ao tty=)"}%% *} )
+  _description open-ttys expl 'open tty'
+else
+  ttys=( /dev/tty?*(N) /dev/pts/^ptmx(N) )
+  ttys=( ${ttys#/dev/} )
+  _description ttys expl 'tty'
+fi
 [[ -z $stripdev ]] && pre=( -p /dev/ )
 
-_description ttys expl 'tty'
 [[ -n $optdev ]] && compadd "$@" "$expl[@]" -M 'r:|/=* r:|=*' -a ttys && return
 compadd "$@" "$expl[@]" "$pre[@]" -M 'r:|/=* r:|=*' -a ttys





                 reply	other threads:[~2018-06-28  8:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=90FE62AE-8433-4C3E-957D-7849153AF375@kba.biglobe.ne.jp \
    --to=takimoto-j@kba.biglobe.ne.jp \
    --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).