zsh-workers
 help / color / mirror / code / Atom feed
* [patch] _init_d add OpenBSD bits
@ 2016-01-10 19:01 Matthew Martin
  2016-01-13  0:57 ` Daniel Shahaf
  0 siblings, 1 reply; 5+ messages in thread
From: Matthew Martin @ 2016-01-10 19:01 UTC (permalink / raw)
  To: zsh-workers

Add a block to complete OpenBSD rc.d scripts. Thanks to llua for
pointing out (M).

Should flags also be a function so it can be overridden?


diff --git a/Completion/Unix/Command/_init_d b/Completion/Unix/Command/_init_d
index bbf62fc..0fd4cc1 100644
--- a/Completion/Unix/Command/_init_d
+++ b/Completion/Unix/Command/_init_d
@@ -41,6 +41,23 @@ if [[ $OSTYPE = freebsd* ]]; then
 
     return 0
   }
+elif [[ $OSTYPE = openbsd* ]]; then
+  (( $+functions[_init_d_fullpath] )) ||
+  _init_d_fullpath() {
+    echo /etc/rc.d/$1
+    return 0
+  }
+
+  (( $+functions[_init_d_get_cmds] )) ||
+  _init_d_get_cmds() {
+    local -a cmds disabled
+
+    cmds=(start stop reload restart check)
+    disabled=(${${${(M)${(f)"$(< $script)"}:#rc_(${(~j:|:)cmds})=NO}#rc_}%=NO})
+    echo ${cmds:|disabled}
+  }
+
+  flags=('-d[print debug information]' '-f[forcibly start the daemon]')
 else
   (( $+functions[_init_d_fullpath] )) ||
   _init_d_fullpath() {
@@ -90,4 +107,4 @@ cmds=( $(_init_d_get_cmds) ) || return
 (( $#cmds )) || zstyle -a ":completion:${curcontext}:commands" commands cmds ||
     cmds=(start stop)
 
-_sub_commands $cmds
+_arguments -s -A "-*" $flags "*:init.d command:_sub_commands $cmds"


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

* Re: [patch] _init_d add OpenBSD bits
  2016-01-10 19:01 [patch] _init_d add OpenBSD bits Matthew Martin
@ 2016-01-13  0:57 ` Daniel Shahaf
  2016-01-13  4:47   ` Matthew Martin
  2016-01-21 19:31   ` Matthew Martin
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Shahaf @ 2016-01-13  0:57 UTC (permalink / raw)
  To: Matthew Martin; +Cc: zsh-workers

Matthew Martin wrote on Sun, Jan 10, 2016 at 13:01:57 -0600:
> +  (( $+functions[_init_d_get_cmds] )) ||
> +  _init_d_get_cmds() {
> +    local -a cmds disabled
> +
> +    cmds=(start stop reload restart check)
> +    disabled=(${${${(M)${(f)"$(< $script)"}:#rc_(${(~j:|:)cmds})=NO}#rc_}%=NO})

Enhancement idea: only populate $disabled if -f isn't on the command line.
(This doesn't block the patch, in my opinion.)

> +    echo ${cmds:|disabled}
> +  }
> +
> +  flags=('-d[print debug information]' '-f[forcibly start the daemon]')
>  else
>    (( $+functions[_init_d_fullpath] )) ||
>    _init_d_fullpath() {
> @@ -90,4 +107,4 @@ cmds=( $(_init_d_get_cmds) ) || return
>  (( $#cmds )) || zstyle -a ":completion:${curcontext}:commands" commands cmds ||
>      cmds=(start stop)
>  
> -_sub_commands $cmds
> +_arguments -s -A "-*" $flags "*:init.d command:_sub_commands $cmds"

Surely these should be single quotes around the last argument?


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

* Re: [patch] _init_d add OpenBSD bits
  2016-01-13  0:57 ` Daniel Shahaf
@ 2016-01-13  4:47   ` Matthew Martin
  2016-01-21 19:31   ` Matthew Martin
  1 sibling, 0 replies; 5+ messages in thread
From: Matthew Martin @ 2016-01-13  4:47 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

On Wed, Jan 13, 2016 at 12:57:34AM +0000, Daniel Shahaf wrote:
> Matthew Martin wrote on Sun, Jan 10, 2016 at 13:01:57 -0600:
> > +  (( $+functions[_init_d_get_cmds] )) ||
> > +  _init_d_get_cmds() {
> > +    local -a cmds disabled
> > +
> > +    cmds=(start stop reload restart check)
> > +    disabled=(${${${(M)${(f)"$(< $script)"}:#rc_(${(~j:|:)cmds})=NO}#rc_}%=NO})
> 
> Enhancement idea: only populate $disabled if -f isn't on the command line.
> (This doesn't block the patch, in my opinion.)

-f overrides <daemon>_flags=NO for the start action like FreeBSD's
onestart. It doesn't override the rc_<action>=NO statements.
> 
> > +    echo ${cmds:|disabled}
> > +  }
> > +
> > +  flags=('-d[print debug information]' '-f[forcibly start the daemon]')
> >  else
> >    (( $+functions[_init_d_fullpath] )) ||
> >    _init_d_fullpath() {
> > @@ -90,4 +107,4 @@ cmds=( $(_init_d_get_cmds) ) || return
> >  (( $#cmds )) || zstyle -a ":completion:${curcontext}:commands" commands cmds ||
> >      cmds=(start stop)
> >  
> > -_sub_commands $cmds
> > +_arguments -s -A "-*" $flags "*:init.d command:_sub_commands $cmds"
> 
> Surely these should be single quotes around the last argument?

Indeed! I didn't realize _arguments parses it's arguments.


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

* Re: [patch] _init_d add OpenBSD bits
  2016-01-13  0:57 ` Daniel Shahaf
  2016-01-13  4:47   ` Matthew Martin
@ 2016-01-21 19:31   ` Matthew Martin
  2016-01-23 23:53     ` Daniel Shahaf
  1 sibling, 1 reply; 5+ messages in thread
From: Matthew Martin @ 2016-01-21 19:31 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

On Wed, Jan 13, 2016 at 12:57:34AM +0000, Daniel Shahaf wrote:
> Surely these should be single quotes around the last argument?

Updated diff after a few more comments from Daniel.


diff --git a/Completion/Unix/Command/_init_d b/Completion/Unix/Command/_init_d
index bbf62fc..2bb8d53 100644
--- a/Completion/Unix/Command/_init_d
+++ b/Completion/Unix/Command/_init_d
@@ -1,6 +1,7 @@
 #compdef -p */(init|rc[0-9S]#).d/*
 
 local cmds script
+local -a flags
 
 _compskip=all
 
@@ -41,6 +42,23 @@ if [[ $OSTYPE = freebsd* ]]; then
 
     return 0
   }
+elif [[ $OSTYPE = openbsd* ]]; then
+  (( $+functions[_init_d_fullpath] )) ||
+  _init_d_fullpath() {
+    echo /etc/rc.d/$1
+    return 0
+  }
+
+  (( $+functions[_init_d_get_cmds] )) ||
+  _init_d_get_cmds() {
+    local -a cmds disabled
+
+    cmds=(start stop reload restart check)
+    disabled=(${${${(M)${(f)"$(< $script)"}:#rc_(${(~j:|:)cmds})=NO}#rc_}%=NO})
+    echo ${cmds:|disabled}
+  }
+
+  flags=('-d[print debug information]' '-f[forcibly start the daemon]')
 else
   (( $+functions[_init_d_fullpath] )) ||
   _init_d_fullpath() {
@@ -90,4 +108,4 @@ cmds=( $(_init_d_get_cmds) ) || return
 (( $#cmds )) || zstyle -a ":completion:${curcontext}:commands" commands cmds ||
     cmds=(start stop)
 
-_sub_commands $cmds
+_arguments -s -A "-*" $flags ':init.d command:_sub_commands $cmds'


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

* Re: [patch] _init_d add OpenBSD bits
  2016-01-21 19:31   ` Matthew Martin
@ 2016-01-23 23:53     ` Daniel Shahaf
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Shahaf @ 2016-01-23 23:53 UTC (permalink / raw)
  To: Matthew Martin; +Cc: zsh-workers

Matthew Martin wrote on Thu, Jan 21, 2016 at 13:31:34 -0600:
> On Wed, Jan 13, 2016 at 12:57:34AM +0000, Daniel Shahaf wrote:
> > Surely these should be single quotes around the last argument?
> 
> Updated diff after a few more comments from Daniel.

Thanks for the patch, applied.

It doesn't complete subcommand names after -f or -d, is that expected
behaviour?  (It's because _sub_commands checks CURRENT.)


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

end of thread, other threads:[~2016-01-23 23:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-10 19:01 [patch] _init_d add OpenBSD bits Matthew Martin
2016-01-13  0:57 ` Daniel Shahaf
2016-01-13  4:47   ` Matthew Martin
2016-01-21 19:31   ` Matthew Martin
2016-01-23 23:53     ` 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).