zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] completion: Add FreeBSD's watch(1)
@ 2015-05-23 10:15 Daniel Shahaf
  2015-06-01 22:19 ` Oliver Kiddle
  2015-06-11 11:24 ` [PATCH] completion: Add FreeBSD's watch(1) Daniel Shahaf
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Shahaf @ 2015-05-23 10:15 UTC (permalink / raw)
  To: zsh-workers

There's a completion for the linux watch(1) at
<https://github.com/zsh-users/zsh-completions/blob/master/src/_watch>.

We may need a _ttys function.

diff --git a/Completion/BSD/Command/_watch-freebsd b/Completion/BSD/Command/_watch-freebsd
new file mode 100644
index 0000000..7302051
--- /dev/null
+++ b/Completion/BSD/Command/_watch-freebsd
@@ -0,0 +1,21 @@
+#autoload
+
+# watch [-cinotW] [-f snpdev] [tty]
+
+# TODO: complete /dev/**/*(+isatty); the following also do so:
+#     Unix/Command/_pgrep
+#     Unix/Command/_gdb
+#     Unix/Command/_qemu
+#     Unix/Command/_ps
+#     Unix/Command/_last
+#     Unix/Type/_ps1234
+
+_arguments -w -S -s : \
+  "-c[Reconnect on close]" \
+  "-f:snp(4) device: " \
+  "-i[Force interactive mode even when stdout is not a tty]" \
+  "-n[Disable the ability to switch the watched tty interactively]" \
+  "-o[Reconnect on overflow]" \
+  "-t[Print date and time at start]" \
+  "-W[Allow write access to observed tty]" \
+  ":tty device: "
diff --git a/Completion/Unix/Command/_watch b/Completion/Unix/Command/_watch
new file mode 100644
index 0000000..7595dac
--- /dev/null
+++ b/Completion/Unix/Command/_watch
@@ -0,0 +1,9 @@
+#compdef watch
+
+# watch(1) has completely different semantics on freebsd compared to linux, hence:
+case $OSTYPE in
+  (freebsd*)  _watch-freebsd "$@"; return $?;;
+  (*)         return 1;;
+esac
+
+# NOTREACHED


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

* Re: [PATCH] completion: Add FreeBSD's watch(1)
  2015-05-23 10:15 [PATCH] completion: Add FreeBSD's watch(1) Daniel Shahaf
@ 2015-06-01 22:19 ` Oliver Kiddle
  2015-06-11 12:09   ` bug with hidden prefixes Oliver Kiddle
  2015-06-11 11:24 ` [PATCH] completion: Add FreeBSD's watch(1) Daniel Shahaf
  1 sibling, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2015-06-01 22:19 UTC (permalink / raw)
  To: zsh-workers

On 23 May, Daniel Shahaf wrote:
> We may need a _ttys function.

That seems like a good idea. The pattern for ttys has been duplicated a
few times and this will make it easier if the system variations in the
device names is more peculiar than we have so far assumed.

This _ttys function allows the /dev/ prefix to be optional, required or
stripped. I think there's a bug somewhere in the hidden prefix handling
that this shows up, however.

Oliver

diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index 48c9d65..f387c87 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -5,17 +5,19 @@ local cur="$words[CURRENT]" prev w list ret=1 expl
 [[ "$PREFIX" = --* ]] &&
     _arguments -- '*=(CORE|SYM)FILE:core file:_files' \
 		  '*=EXECFILE:executable:_files -g \*\(-\*\)' \
-		  '*=TTY:terminal device:compadd /dev/tty\*' && return 0
+		  '*=TTY:terminal device:_ttys' && return 0
 
 if compset -P '-(cd|directory)='; then
   _files -/
 elif compset -P '-tty='; then
-  _wanted devices expl 'terminal device' compadd - /dev/tty*
+  _wanted devices expl 'terminal device' _ttys
 elif compset -P '-(exec|se)='; then
   _description files expl executable
   _files "$expl[@]" -g '*(-*)'
 elif compset -P '-(symbols|core|command)='; then
   _files
+elif compset -P '--pid='; then
+  _pids
 elif [[ "$PREFIX" = -* ]]; then
   _tags options
   while _tags; do
diff --git a/Completion/Unix/Command/_last b/Completion/Unix/Command/_last
index 706d82f..f198e0f 100644
--- a/Completion/Unix/Command/_last
+++ b/Completion/Unix/Command/_last
@@ -9,7 +9,7 @@ for pattern arg in \
   '((free|net|open)bsd*|darwin*|dragonfly*|linux-gnu)' '-h[limit sessions by hostname]:host:_hosts' \
   '((free|open)bsd*|linux-gnu)' '-s[report duration in seconds]' \
   '(freebsd*|openbsd*)' '-d[limit sessions to those active at snapshot time]:time ([[CC]YY][MMDD]hhmm[.SS])' \
-  '((net|free|open)bsd*|darwin*|dragonfly*)' '-t[limit sessions by tty]:tty:compadd -a ttys' \
+  '((net|free|open)bsd*|darwin*|dragonfly*)' '-t[limit sessions by tty]:tty:_ttys -D' \
   'openbsd*' '-c[calculate total time]' \
   '^darwin*' '-f[specify account file]:file:_files' \
   '(solaris*|linux-gnu|freebsd*|openbsd*)' '-n[specify number of lines to show]:number' \
@@ -45,7 +45,7 @@ case $OSTYPE in
 esac
 
 if [[ $OSTYPE = (linux-gnu|solaris*) ]]; then
-  args+=( '*:arg: _alternative "users:user:_users" "ttys:tty:compadd -a ttys"' )
+  args+=( '*:arg: _alternative "users:user:_users" "ttys:tty:_ttys -d" "ttys:tty:(reboot)"' )
 else
   args+=( '*:user:_users' )
 fi
diff --git a/Completion/Unix/Command/_pgrep b/Completion/Unix/Command/_pgrep
index d3dcd18..0b7d23d 100644
--- a/Completion/Unix/Command/_pgrep
+++ b/Completion/Unix/Command/_pgrep
@@ -13,7 +13,7 @@ arguments=('-P[parent process id]:parent process id:->ppid'
      '-M[extract the name list from the specified core]:files:_files'
      '-N[extract the name list from the specified system]:files:_files'
      '-s[match only session id]:session id:->sid'
-     '-t[match only controlled by terminal]:terminal device:->tty'
+     '-t[match only controlled by terminal]:terminal device:_sequence _ttys -d'
      '-T[match only in processes specified routing table in rtable]'
      '-u[match only effective user id]:user:_users'
      '-U[match only real user id]:user:_users'
@@ -69,12 +69,6 @@ arguments=( ${(M)arguments:#(|\*)(|\(*\))-[$optchars]*}
 _arguments -C -s -w $arguments && ret=0
 
 case $state in
-  (tty)
-    local -a ttys
-    ttys=( /dev/tty*(N) /dev/pts/*(N) )
-    _sequence -s , _wanted tty expl 'terminal device' compadd - ${ttys#/dev/}
-    ;;
-
   (sid)
     if [[ $OSTYPE == openbsd* ]]; then
       break
diff --git a/Completion/Unix/Command/_ps b/Completion/Unix/Command/_ps
index e557b27..6f67f79 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 , compadd - /dev/pts/<->(N\:s/\\/dev\\//) /dev/tty*(N\:t)'
+  '*-t+[select processes by attached terminal]:tty:_sequence -s , _ttys -D'
   '*-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 -'
@@ -163,8 +163,7 @@ if (( CURRENT > 1 )) && [[ $OSTYPE != solaris* || ( $OSTYPE = linux-gnu && $word
     *J) _sequence _jails -0 && return ;;
     *[MNW]) _files && return ;;
     *t)
-      _wanted -C option-t-1 ttys expl tty _sequence -s , \
-	  compadd - /dev/pts/<->(N\:s/\\/dev\\//) /dev/tty*(N\:t) && return
+      _wanted -C option-t-1 ttys expl tty _sequence -s , _ttys -D && return
     ;;
     *p) _wanted -C option-p-1 processes expl 'process ID' _sequence -s , _pids && return;;
     *U) _wanted -C option-U-1 users expl user _sequence -s , _users && return ;;
diff --git a/Completion/Unix/Type/_ttys b/Completion/Unix/Type/_ttys
new file mode 100644
index 0000000..5e55985
--- /dev/null
+++ b/Completion/Unix/Type/_ttys
@@ -0,0 +1,19 @@
+#autoload
+
+# Options:
+#
+# -d  strip /dev/ prefix from matches
+# -D  matches allowed with or without /dev/ prefix
+
+local -a ttys expl pre
+local stripdev optdev
+
+zparseopts -D -K -E d=stripdev D=optdev
+
+ttys=( /dev/tty?*(N) /dev/pts/^ptmx(N) )
+ttys=( ${ttys#/dev/} )
+[[ -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


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

* Re: [PATCH] completion: Add FreeBSD's watch(1)
  2015-05-23 10:15 [PATCH] completion: Add FreeBSD's watch(1) Daniel Shahaf
  2015-06-01 22:19 ` Oliver Kiddle
@ 2015-06-11 11:24 ` Daniel Shahaf
  1 sibling, 0 replies; 7+ messages in thread
From: Daniel Shahaf @ 2015-06-11 11:24 UTC (permalink / raw)
  To: zsh-workers

Daniel Shahaf wrote on Sat, May 23, 2015 at 10:15:55 +0000:
> There's a completion for the linux watch(1) at
> <https://github.com/zsh-users/zsh-completions/blob/master/src/_watch>.
> 

I haven't committed this because I need to integrate an offlist review
by Oliver (thanks!) and use his new _ttys function.

Daniel

> We may need a _ttys function.
> 
> diff --git a/Completion/BSD/Command/_watch-freebsd b/Completion/BSD/Command/_watch-freebsd


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

* bug with hidden prefixes
  2015-06-01 22:19 ` Oliver Kiddle
@ 2015-06-11 12:09   ` Oliver Kiddle
  2015-06-11 15:45     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Oliver Kiddle @ 2015-06-11 12:09 UTC (permalink / raw)
  To: zsh-workers

On 2 Jun, I wrote:
> This _ttys function allows the /dev/ prefix to be optional, required or
> stripped. I think there's a bug somewhere in the hidden prefix handling
> that this shows up, however.

I'll just elaborate on this in case someone else has more success than
me in tracking this down. The bug exists even in zsh 3.1.7 so is not
something that got introduced later. The following are the minimal steps
to reproduce it:

_foo() {
  local ret=1
  compadd -p /dev/ -M 'r:|/=* r:|=*' one two && ret=0
  compadd three && ret=0
  return ret
}
compdef _foo foo
foo /d<tab>

This should insert /dev/ because it is an unambiguous prefix to both
possible matches: three can be ruled out. The two matches are listed, it
is just that the prefix is not inserted. Without either the matching
control or the third match being there, it works.

Oliver


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

* Re: bug with hidden prefixes
  2015-06-11 12:09   ` bug with hidden prefixes Oliver Kiddle
@ 2015-06-11 15:45     ` Bart Schaefer
  2015-06-11 15:53       ` Roman Neuhauser
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2015-06-11 15:45 UTC (permalink / raw)
  To: zsh-workers

On Jun 11,  2:09pm, Oliver Kiddle wrote:
}
} _foo() {
}   local ret=1
}   compadd -p /dev/ -M 'r:|/=* r:|=*' one two && ret=0
}   compadd three && ret=0
}   return ret
} }
} compdef _foo foo
} foo /d<tab>
} 
} This should insert /dev/ because it is an unambiguous prefix to both
} possible matches: three can be ruled out. The two matches are listed, it
} is just that the prefix is not inserted. Without either the matching
} control or the third match being there, it works.

Hmm.  When I use this with "compadd three" removed, I get exactly the
same behavior as with it included:

torch% _foo() {    
  local ret=1
  compadd -p /dev/ -M 'r:|/=** r:|=*' one two && ret=0
:  compadd three && ret=0
  return ret
}
torch% foo /d<TAB>
one  two

That is, no prefix is inserted, just the possible matches are listed.
The only way I get different behavior is to remove the -M spec.

torch% _foo() {            
  local ret=1
  compadd -p /dev/ one two && ret=0 
  compadd three && ret=0 
  return ret
}
torch% foo /d<TAB>
torch% foo /dev/

I have no additional clues but perhaps this rules out some red herrings.


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

* Re: bug with hidden prefixes
  2015-06-11 15:45     ` Bart Schaefer
@ 2015-06-11 15:53       ` Roman Neuhauser
  2015-06-11 16:35         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Roman Neuhauser @ 2015-06-11 15:53 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

# schaefer@brasslantern.com / 2015-06-11 08:45:58 -0700:
> On Jun 11,  2:09pm, Oliver Kiddle wrote:
> }
> } _foo() {
> }   local ret=1
> }   compadd -p /dev/ -M 'r:|/=* r:|=*' one two && ret=0
> }   compadd three && ret=0
> }   return ret
> } }
> } compdef _foo foo
> } foo /d<tab>
> } 
> } This should insert /dev/ because it is an unambiguous prefix to both
> } possible matches: three can be ruled out. The two matches are listed, it
> } is just that the prefix is not inserted. Without either the matching
> } control or the third match being there, it works.
> 
> Hmm.  When I use this with "compadd three" removed, I get exactly the
> same behavior as with it included:
> 
> torch% _foo() {    
>   local ret=1
>   compadd -p /dev/ -M 'r:|/=** r:|=*' one two && ret=0
> :  compadd three && ret=0
>   return ret
> }

it's not actually removed, instead it clobbers ret with 0 no matter
what the previous compadd did.

-- 
roman


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

* Re: bug with hidden prefixes
  2015-06-11 15:53       ` Roman Neuhauser
@ 2015-06-11 16:35         ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2015-06-11 16:35 UTC (permalink / raw)
  To: Roman Neuhauser; +Cc: Zsh hackers list

[-- Attachment #1: Type: text/plain, Size: 450 bytes --]

On Jun 11, 2015 8:53 AM, "Roman Neuhauser" <neuhauser@sigpipe.cz> wrote:
>
> # schaefer@brasslantern.com / 2015-06-11 08:45:58 -0700:
> >
> > torch% _foo() {
> >   local ret=1
> >   compadd -p /dev/ -M 'r:|/=** r:|=*' one two && ret=0
> > :  compadd three && ret=0
> >   return ret
> > }
>
> it's not actually removed, instead it clobbers ret with 0 no matter
> what the previous compadd did.

Doesn't actually matter as the compadd always succeeds.

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

end of thread, other threads:[~2015-06-11 16:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-23 10:15 [PATCH] completion: Add FreeBSD's watch(1) Daniel Shahaf
2015-06-01 22:19 ` Oliver Kiddle
2015-06-11 12:09   ` bug with hidden prefixes Oliver Kiddle
2015-06-11 15:45     ` Bart Schaefer
2015-06-11 15:53       ` Roman Neuhauser
2015-06-11 16:35         ` Bart Schaefer
2015-06-11 11:24 ` [PATCH] completion: Add FreeBSD's watch(1) Daniel Shahaf

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