Subject: Re: [patch] Completions for cu, fw_update, and rcctl
From: Matthew Martin <[email-masked]>
To: Daniel Shahaf <[email-masked]>
Cc: [email-masked]
Date: Tue, 12 Jan 2016 22:58:53 -0600
List-Id: Zsh Workers List <zsh-workers.zsh.org>

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