zsh-workers
 help / color / mirror / code / Atom feed
* [patch] Completions for cu, fw_update, and rcctl
@ 2016-01-10  7:51 Matthew Martin
  2016-01-10 19:53 ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Matthew Martin @ 2016-01-10  7:51 UTC (permalink / raw)
  To: zsh-workers

Few completers for OpenBSD utilities that have been sitting in my tree.

Not sure if listing line speeds is overkill (fine by me to remove them
if anyone thinks it is).


diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
new file mode 100644
index 0000000..d4658e3
--- /dev/null
+++ b/Completion/BSD/Command/_cu
@@ -0,0 +1,7 @@
+#compdef cu
+
+_arguments -s -A '-*' \
+  '-d[do not block waiting for a carrier to be detected]' \
+  '-l[line to use]:line:(/dev/cuaU#<->(%))' \
+  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
+  '(-*)1:host:'
diff --git a/Completion/BSD/Command/_fw_update b/Completion/BSD/Command/_fw_update
new file mode 100644
index 0000000..b01749f
--- /dev/null
+++ b/Completion/BSD/Command/_fw_update
@@ -0,0 +1,10 @@
+#compdef fw_update
+
+_arguments -s -S -A "-*" \
+  '(*)-a[install or update firmware for all drivers]' \
+  '-d[delete drivers instead of adding them]' \
+  '-i[display information]' \
+  '-n[dry run]' \
+  '-p[use the firmware at specified path]:path:' \
+  '*-v[verbose output]' \
+  '(-a)*:driver:'
diff --git a/Completion/BSD/Command/_rcctl b/Completion/BSD/Command/_rcctl
new file mode 100644
index 0000000..24fa04f
--- /dev/null
+++ b/Completion/BSD/Command/_rcctl
@@ -0,0 +1,42 @@
+#compdef rcctl
+
+local context state line
+local -a actions subcmds variables
+
+actions=(check reload restart start stop)
+subcmds=(disable enable get getdef ls order set)
+variables=(class flags status timeout user)
+
+if [[ $service == "rcctl" ]]; then
+  _arguments -C \
+    '-d[print debug information]' \
+    '-f[forcibly start the daemon]' \
+    ':subcommand:('"$actions ${${${+words[(r)-[df]]}#1}/0/$subcmds}"\) \
+    '*:: :->subcmd' && return
+  service="$words[1]"
+fi
+
+case $service in
+  get|getdef)
+    _arguments \
+      ':service:_services' \
+      ':variable:compadd -a variables'
+    ;;
+  ls)
+     _arguments ':display a list of services and daemons matching:(all faulty off on started stopped)'
+    ;;
+  order)
+    _arguments \
+      ':service to start first:_services'
+      '*:service to start next:_services'
+    ;;
+  set)
+    _arguments \
+      ':service:_services' \
+      ':variable:compadd -a variables' \
+      '*:argument:'
+    ;;
+  ${(~j:|:)actions}|disable|enable)
+    _arguments "*:service to $words[2]:_services"
+    ;;
+esac


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

* Re: [patch] Completions for cu, fw_update, and rcctl
  2016-01-10  7:51 [patch] Completions for cu, fw_update, and rcctl Matthew Martin
@ 2016-01-10 19:53 ` Daniel Shahaf
  2016-01-13  4:58   ` Matthew Martin
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Shahaf @ 2016-01-10 19:53 UTC (permalink / raw)
  To: Matthew Martin; +Cc: zsh-workers

Matthew Martin wrote on Sun, Jan 10, 2016 at 01:51:41 -0600:
> Few completers for OpenBSD utilities that have been sitting in my tree.
> 
> Not sure if listing line speeds is overkill (fine by me to remove them
> if anyone thinks it is).

I think it's a nice touch.  When I work with cu the last thing I want is
to have to remember whether the magic number is 115200 or 112500 ☺

> diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
> new file mode 100644
> index 0000000..d4658e3
> --- /dev/null
> +++ b/Completion/BSD/Command/_cu
> @@ -0,0 +1,7 @@
> +#compdef cu
> +
> +_arguments -s -A '-*' \
> +  '-d[do not block waiting for a carrier to be detected]' \
> +  '-l[line to use]:line:(/dev/cuaU#<->(%))' \

I'm surprised a glob pattern works inside the parentheses.  I'd have
expected a call to _files would be needed.

On Linux the device is called /dev/ttyS0, so the pattern could be:
    /dev/(cuaU#<->|ttyS<->)(N%c)
? [with (N) to support other OSes]

Maybe encapsulate this as Completion/Unix/Type/_tty_lines so screen(1)
and friends can reuse it in the future?

> +  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
> +  '(-*)1:host:'

Haven't looked at the rest.

Daniel


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

* Re: [patch] Completions for cu, fw_update, and rcctl
  2016-01-10 19:53 ` Daniel Shahaf
@ 2016-01-13  4:58   ` Matthew Martin
  2016-01-13  5:04     ` Matthew Martin
  2016-01-14  0:13     ` Daniel Shahaf
  0 siblings, 2 replies; 5+ messages in thread
From: Matthew Martin @ 2016-01-13  4:58 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

On Sun, Jan 10, 2016 at 07:53:22PM +0000, Daniel Shahaf wrote:
> Matthew Martin wrote on Sun, Jan 10, 2016 at 01:51:41 -0600:
> > Few completers for OpenBSD utilities that have been sitting in my tree.
> > 
> > Not sure if listing line speeds is overkill (fine by me to remove them
> > if anyone thinks it is).
> 
> I think it's a nice touch.  When I work with cu the last thing I want is
> to have to remember whether the magic number is 115200 or 112500 ???
> 
> > diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
> > new file mode 100644
> > index 0000000..d4658e3
> > --- /dev/null
> > +++ b/Completion/BSD/Command/_cu
> > @@ -0,0 +1,7 @@
> > +#compdef cu
> > +
> > +_arguments -s -A '-*' \
> > +  '-d[do not block waiting for a carrier to be detected]' \
> > +  '-l[line to use]:line:(/dev/cuaU#<->(%))' \
> 
> I'm surprised a glob pattern works inside the parentheses.  I'd have
> expected a call to _files would be needed.
> 
> On Linux the device is called /dev/ttyS0, so the pattern could be:
>     /dev/(cuaU#<->|ttyS<->)(N%c)
> ? [with (N) to support other OSes]
> 
> Maybe encapsulate this as Completion/Unix/Type/_tty_lines so screen(1)
> and friends can reuse it in the future?

Like so? Made a _tty_speeds too.


diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
index bdd5795..7b5ab7e 100644
--- a/Completion/BSD/Command/_cu
+++ b/Completion/BSD/Command/_cu
@@ -2,6 +2,6 @@
 
 _arguments -s -A '-*' \
   '-d[do not block waiting for a carrier to be detected]' \
-  '-l[line to use]:line:(/dev/(cuaU#<->|ttyS<->)(N%c))' \
-  '-s[line speed]:line speed:(75 110 300 1200 2400 4800 9600 19200 38400 57600 115200)' \
+  '-l[line to use]:line:_tty_lines' \
+  '-s[line speed]:line speed:_tty_speeds' \
   '(-*)1:host:'
diff --git a/Completion/Unix/Command/_gdb b/Completion/Unix/Command/_gdb
index e9c3339..77f0001 100644
--- a/Completion/Unix/Command/_gdb
+++ b/Completion/Unix/Command/_gdb
@@ -37,9 +37,7 @@ else
   (-[csx]) _files && return 0 ;;
   (-e)     _description files expl executable
            _files "$expl[@]" -g '*(-*)' && return 0 ;;
-  (-b)     _wanted -V values expl 'baud rate' \
-               compadd 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
-		       9600 19200 38400 57600 115200 230400 && return 0 ;;
+  (-b)     _tty_speeds && return 0 ;;
   esac
 
   w=( "${(@)words[2,-1]}" )
diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
index 96ad0a4..7ac85df 100644
--- a/Completion/Unix/Command/_joe
+++ b/Completion/Unix/Command/_joe
@@ -3,7 +3,7 @@
 _arguments \
   '-asis[characters with codes >127 will be displayed non-inverted]' \
   '-backpath[backup file directory]:backup file directory:_files -/' \
-  '-baud[inserts delays for baud rates below 19200]:baud rate:(57600 38400 19200 9600 4800 2400 1200 300)' \
+  '-baud[inserts delays for baud rates below 19200]:baud rate:_tty_speed' \
   '-beep[beep on command errors or when cursor goes past extremes]' \
   '-columns[sets the number of screen columns]:num of columns' \
   '-csmode[continued search mode]' \
diff --git a/Completion/Unix/Command/_screen b/Completion/Unix/Command/_screen
index 510fd71..b08a729 100644
--- a/Completion/Unix/Command/_screen
+++ b/Completion/Unix/Command/_screen
@@ -97,9 +97,9 @@ if [[ -n $state ]]; then
   case $state in
     normal)
       if (( CURRENT == 1 )) && [[ $PREFIX == /dev/* ]]; then
-	  _path_files -g '*(%)'
+	  _tty_lines
       elif (( CURRENT == 2 )) && [[ ${words[1]} == /dev/* ]]; then
-	  _message "baud rate"
+	  _tty_speeds
       elif (( CURRENT > 2 )) && [[ ${words[1]} == /dev/* ]]; then
 	  _message "no more parameters"
       else
diff --git a/Completion/Unix/Type/_tty_lines b/Completion/Unix/Type/_tty_lines
new file mode 100644
index 0000000..2d9d097
--- /dev/null
+++ b/Completion/Unix/Type/_tty_lines
@@ -0,0 +1,7 @@
+#autoload
+
+local expl
+
+_description files expl 'tty line'
+
+_files -g '/dev/(cuaU#<->|ttyS<->)(N%c)'
diff --git a/Completion/Unix/Type/_tty_speeds b/Completion/Unix/Type/_tty_speeds
new file mode 100644
index 0000000..ac82d60
--- /dev/null
+++ b/Completion/Unix/Type/_tty_speeds
@@ -0,0 +1,7 @@
+#autoload
+
+local expl
+
+_description 'tty speed' expl 'tty speed'
+
+compadd -- 75 110 300 1200 2400 4800 9600 19200 38400 57600 115200


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

* Re: [patch] Completions for cu, fw_update, and rcctl
  2016-01-13  4:58   ` Matthew Martin
@ 2016-01-13  5:04     ` Matthew Martin
  2016-01-14  0:13     ` Daniel Shahaf
  1 sibling, 0 replies; 5+ messages in thread
From: Matthew Martin @ 2016-01-13  5:04 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

On Tue, Jan 12, 2016 at 10:58:53PM -0600, Matthew Martin wrote:
> diff --git a/Completion/Unix/Command/_joe b/Completion/Unix/Command/_joe
> index 96ad0a4..7ac85df 100644
> --- a/Completion/Unix/Command/_joe
> +++ b/Completion/Unix/Command/_joe
> @@ -3,7 +3,7 @@
>  _arguments \
>    '-asis[characters with codes >127 will be displayed non-inverted]' \
>    '-backpath[backup file directory]:backup file directory:_files -/' \
> -  '-baud[inserts delays for baud rates below 19200]:baud rate:(57600 38400 19200 9600 4800 2400 1200 300)' \
> +  '-baud[inserts delays for baud rates below 19200]:baud rate:_tty_speed' \

This should of course be _tty_speeds with the s. Sorry for the noise.

>    '-beep[beep on command errors or when cursor goes past extremes]' \
>    '-columns[sets the number of screen columns]:num of columns' \
>    '-csmode[continued search mode]' \


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

* Re: [patch] Completions for cu, fw_update, and rcctl
  2016-01-13  4:58   ` Matthew Martin
  2016-01-13  5:04     ` Matthew Martin
@ 2016-01-14  0:13     ` Daniel Shahaf
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2016-01-14  0:13 UTC (permalink / raw)
  To: Matthew Martin; +Cc: zsh-workers

Matthew Martin wrote on Tue, Jan 12, 2016 at 22:58:53 -0600:
> On Sun, Jan 10, 2016 at 07:53:22PM +0000, Daniel Shahaf wrote:
> > Matthew Martin wrote on Sun, Jan 10, 2016 at 01:51:41 -0600:
> > > Few completers for OpenBSD utilities that have been sitting in my tree.
> > > 
> > > Not sure if listing line speeds is overkill (fine by me to remove them
> > > if anyone thinks it is).
> > 
> > I think it's a nice touch.  When I work with cu the last thing I want is
> > to have to remember whether the magic number is 115200 or 112500 ???
> > 
> > > diff --git a/Completion/BSD/Command/_cu b/Completion/BSD/Command/_cu
> > > new file mode 100644
> > > index 0000000..d4658e3
> > > --- /dev/null
> > > +++ b/Completion/BSD/Command/_cu
> > > @@ -0,0 +1,7 @@
> > > +#compdef cu
> > > +
> > > +_arguments -s -A '-*' \
> > > +  '-d[do not block waiting for a carrier to be detected]' \
> > > +  '-l[line to use]:line:(/dev/cuaU#<->(%))' \
> > 
> > I'm surprised a glob pattern works inside the parentheses.  I'd have
> > expected a call to _files would be needed.
> > 
> > On Linux the device is called /dev/ttyS0, so the pattern could be:
> >     /dev/(cuaU#<->|ttyS<->)(N%c)
> > ? [with (N) to support other OSes]
> > 
> > Maybe encapsulate this as Completion/Unix/Type/_tty_lines so screen(1)
> > and friends can reuse it in the future?
> 
> Like so? Made a _tty_speeds too.

Thanks for going through the existing completion functions!

> +++ b/Completion/Unix/Command/_gdb
> @@ -37,9 +37,7 @@ else
> -  (-b)     _wanted -V values expl 'baud rate' \
> -               compadd 0 50 75 110 134 150 200 300 600 1200 1800 2400 4800 \
> -		       9600 19200 38400 57600 115200 230400 && return 0 ;;
> +  (-b)     _tty_speeds && return 0 ;;

> diff --git a/Completion/Unix/Type/_tty_speeds b/Completion/Unix/Type/_tty_speeds
> new file mode 100644
> index 0000000..ac82d60
> --- /dev/null
> +++ b/Completion/Unix/Type/_tty_speeds
> @@ -0,0 +1,7 @@
> +#autoload
> +
> +local expl
> +
> +_description 'tty speed' expl 'tty speed'

The first 'tty speed' argument is the tag.  Conventionally, tag names
don't contain spaces.  (You can type <C-X><h> to view tag names.)  The
tag name can be 'values' or perhaps 'tty-speeds'.  The incumbent code
uses 'values', at least in one place.

The second 'tty speed' argument is the description.  Since I set «zstyle
':completion:*:descriptions' format '> %d'», I expect that argument to
be displayed as a "> tty speed" line above the suggested completions
when I do «cu -s <TAB>»; however, there is no such line.

It seems you don't pass "$expl[@]" to compadd, contrary to the example
in the docs of _description.

Or perhaps the 'compadd' should be wrapped by a _wanted, as in
   _wanted values expl 'tty speed' compadd -- 75 110 ...

> +compadd -- 75 110 300 1200 2400 4800 9600 19200 38400 57600 115200
> 

I suppose the 230400 from _gdb should be added here, too?

> diff --git a/Completion/Unix/Type/_tty_lines b/Completion/Unix/Type/_tty_lines
> new file mode 100644
> index 0000000..2d9d097
> --- /dev/null
> +++ b/Completion/Unix/Type/_tty_lines
> @@ -0,0 +1,7 @@
> +#autoload
> +
> +local expl
> +
> +_description files expl 'tty line'
> +
> +_files -g '/dev/(cuaU#<->|ttyS<->)(N%c)'

Here, too, the 'tty line' description isn't shown to the user.

«cu -l /dev/<TAB>» offers only immediate subdirectories of /dev, but
doesn't offer the line device names, even though «cu -l <TAB>» does.
I suspect _files assumes the pattern doesn't start with a slash.
(This issue particularly affects _screen: that function won't call
into _tty_lines until PREFIX=/dev/, so your patch effectively breaks
«screen /dev/<TAB>».)

«cu -l <TAB>» offers both /dev/ttyS<-> and immediate subdirectories of
cwd; the latter is probably unnecessary.

When cwd is /dev, «cu -l tty<TAB>» offers all tty devices, not only
those whose names match ttyS<->.

Cheers,

Daniel


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

end of thread, other threads:[~2016-01-14  0:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-10  7:51 [patch] Completions for cu, fw_update, and rcctl Matthew Martin
2016-01-10 19:53 ` Daniel Shahaf
2016-01-13  4:58   ` Matthew Martin
2016-01-13  5:04     ` Matthew Martin
2016-01-14  0:13     ` 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).