From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28176 invoked by alias); 28 Jun 2018 08:19:08 -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: 43107 Received: (qmail 2142 invoked by uid 1010); 28 Jun 2018 08:19:08 -0000 X-Qmail-Scanner-Diagnostics: from rcpt-mqugw.biglobe.ne.jp 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(133.208.100.2):SA:0(-2.6/5.0):. Processed in 1.287713 secs); 28 Jun 2018 08:19:08 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: takimoto-j@kba.biglobe.ne.jp X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Biglobe-Sender: From: Jun T Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [PATCH] _ttys: complete only active ttys Message-Id: <90FE62AE-8433-4C3E-957D-7849153AF375@kba.biglobe.ne.jp> Date: Thu, 28 Jun 2018 16:39:08 +0900 To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) X-Biglobe-Spnum: 51982 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=3D( '*-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 !=3D = (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 =20 local -a ttys expl pre -local stripdev optdev +local stripdev optdev open =20 -zparseopts -D -K -E d=3Dstripdev D=3Doptdev +zparseopts -D -K -E d=3Dstripdev D=3Doptdev o=3Dopen =20 -ttys=3D( /dev/tty?*(N) /dev/pts/^ptmx(N) ) -ttys=3D( ${ttys#/dev/} ) +if [[ -n $open ]]; then + ttys=3D( ${(u)${(f)"$(_call_program open-ttys ps -ao tty=3D)"}%% *} ) + _description open-ttys expl 'open tty' +else + ttys=3D( /dev/tty?*(N) /dev/pts/^ptmx(N) ) + ttys=3D( ${ttys#/dev/} ) + _description ttys expl 'tty' +fi [[ -z $stripdev ]] && pre=3D( -p /dev/ ) =20 -_description ttys expl 'tty' [[ -n $optdev ]] && compadd "$@" "$expl[@]" -M 'r:|/=3D* r:|=3D*' -a = ttys && return compadd "$@" "$expl[@]" "$pre[@]" -M 'r:|/=3D* r:|=3D*' -a ttys