zsh-workers
 help / color / mirror / code / Atom feed
* a compdef for FreeBSD's sysctl(8) command
@ 2001-07-03  5:52 Akinori MUSHA
  2001-07-03  6:31 ` Andrej Borsenkow
  2001-07-03 10:49 ` Oliver Kiddle
  0 siblings, 2 replies; 8+ messages in thread
From: Akinori MUSHA @ 2001-07-03  5:52 UTC (permalink / raw)
  To: zsh-workers

Hi,

Attached is a compdef for FreeBSD's sysctl(8) command which gets or
sets kernel state.  It was reviewed in a public mailing list.

Would you please merge this?

Thanks in advance.

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Freeze this moment a little bit longer, make each impression
  a little bit stronger..  Experience slips away -- Time stand still"

#compdef sysctl

case `uname -sr` in
FreeBSD\ [0-4].*)
    (( $+functions[_sysctl_variables] )) ||
    _sysctl_variables() {
	local ret=1 sup=' '

	(( $words[(I)-*w*] )) && sup='='

	compadd "$@" -S $sup - $(sysctl -A | sed 's/:.*//') && ret=0

	return ret
    }

    _arguments -s \
     '-a[list all]' \
     '-A[show all opaques (values suppressed)]' \
     '-b[binary output]' \
     '-n[show only variable values]' \
     '-w[write mode]' \
     '-X[show all opaques (entire values)]' \
     '*:variable:_sysctl_variables'
    ;;
FreeBSD\ [5-9].*)
    _arguments -s \
     '-a[list all]' \
     '-b[binary output]' \
     '-N[show only variable names]' \
     '-n[show only variable values]' \
     '-o[show opaques as well (values suppressed)]' \
     '-x[show opaques as well (entire values)]' \
     '*:variable:compadd -S "" - $(sysctl -aN)'
    ;;
esac


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

* RE: a compdef for FreeBSD's sysctl(8) command
  2001-07-03  5:52 a compdef for FreeBSD's sysctl(8) command Akinori MUSHA
@ 2001-07-03  6:31 ` Andrej Borsenkow
  2001-07-03 10:49 ` Oliver Kiddle
  1 sibling, 0 replies; 8+ messages in thread
From: Andrej Borsenkow @ 2001-07-03  6:31 UTC (permalink / raw)
  To: zsh-workers

Just to comment that it exists in Linux as well.

> -----Original Message-----
> From: Akinori MUSHA [mailto:knu@iDaemons.org]
> Sent: Tuesday, July 03, 2001 9:52 AM
> To: zsh-workers@sunsite.auc.dk
> Subject: a compdef for FreeBSD's sysctl(8) command
> 
> 
> Hi,
> 
> Attached is a compdef for FreeBSD's sysctl(8) command which gets or
> sets kernel state.  It was reviewed in a public mailing list.
> 
> Would you please merge this?
> 
> Thanks in advance.
> 
> -- 
>                      /
>                     /__  __            Akinori.org / MUSHA.org
>                    / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
> Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp
> 
> "Freeze this moment a little bit longer, make each impression
>   a little bit stronger..  Experience slips away -- Time stand still"
> 
> #compdef sysctl
> 
> case `uname -sr` in
> FreeBSD\ [0-4].*)
>     (( $+functions[_sysctl_variables] )) ||
>     _sysctl_variables() {
> 	local ret=1 sup=' '
> 
> 	(( $words[(I)-*w*] )) && sup='='
> 
> 	compadd "$@" -S $sup - $(sysctl -A | sed 's/:.*//') && ret=0
> 
> 	return ret
>     }
> 
>     _arguments -s \
>      '-a[list all]' \
>      '-A[show all opaques (values suppressed)]' \
>      '-b[binary output]' \
>      '-n[show only variable values]' \
>      '-w[write mode]' \
>      '-X[show all opaques (entire values)]' \
>      '*:variable:_sysctl_variables'
>     ;;
> FreeBSD\ [5-9].*)
>     _arguments -s \
>      '-a[list all]' \
>      '-b[binary output]' \
>      '-N[show only variable names]' \
>      '-n[show only variable values]' \
>      '-o[show opaques as well (values suppressed)]' \
>      '-x[show opaques as well (entire values)]' \
>      '*:variable:compadd -S "" - $(sysctl -aN)'
>     ;;
> esac
> 
> 


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

* Re: a compdef for FreeBSD's sysctl(8) command
  2001-07-03  5:52 a compdef for FreeBSD's sysctl(8) command Akinori MUSHA
  2001-07-03  6:31 ` Andrej Borsenkow
@ 2001-07-03 10:49 ` Oliver Kiddle
  2001-07-03 11:16   ` Akinori MUSHA
  1 sibling, 1 reply; 8+ messages in thread
From: Oliver Kiddle @ 2001-07-03 10:49 UTC (permalink / raw)
  To: Akinori MUSHA; +Cc: zsh-workers

Akinori MUSHA wrote:

> Attached is a compdef for FreeBSD's sysctl(8) command which gets or
> sets kernel state.  It was reviewed in a public mailing list.
> 
> Would you please merge this?

Thanks, I'll merge that a bit later.

First though, I've just tried to adapt it to also work for Linux. I
also replaced your function with a substitution which I think should
do the same thing so I would appreciate if you could check that the
updated function below still works.

I don't suppose that $OSTYPE on FreeBSD includes any of the FreeBSD
version. It is just that it is a tiny bit faster to check than
`uname -sr`?

If `sysctl -A' or `sysctl -aN' is run as a non-root user, do you get
any output to stderr (you do on Linux)? If so, we need to add a
redirection.

Does anyone on zsh-workers mind if I put this on the stable branch.
Mainly because I suspect the FreeBSD folks would otherwise be
maintaining it as a patch for their port.

Oliver

#compdef sysctl

case `uname -sr` in
  FreeBSD\ [0-4].*)
    _arguments -s \
      '-a[list all]' \
      '-A[show all opaques (values suppressed)]' \
      '-b[binary output]' \
      '-n[show only variable values]' \
      '-w[write mode]' \
      '-X[show all opaques (entire values)]' \
      "*:sysctl variable:compadd ${words[(r)-w]:+-S =} $(sysctl -A | sed 's/:.*//')"
  ;;
  FreeBSD\ [5-9].*)
    _arguments -s \
      '-a[list all]' \
      '-b[binary output]' \
      '-N[show only variable names]' \
      '-n[show only variable values]' \
      '-o[show opaques as well (values suppressed)]' \
      '-x[show opaques as well (entire values)]' \
      '*:sysctl variable:compadd -S "" - $(sysctl -aN)'
  ;;
  Linux*)
    _arguments -A "-*" \
      '-n[show only variable values]' \
      '(-n -p -a -A)-w[write mode]' \
      '(-n -w -a -A *)-p[specify file to load sysctl settings from]:file:_files' \
      '(-n -w -p -A *)-a[list all]' \
      '(-n -w -p -a *)-A[list all in table form]' \
      '(-n -p -a -A)*:sysctl variable:_files -W /proc/sys'
  ;;
esac

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


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

* Re: a compdef for FreeBSD's sysctl(8) command
  2001-07-03 10:49 ` Oliver Kiddle
@ 2001-07-03 11:16   ` Akinori MUSHA
  2001-07-03 16:28     ` Bart Schaefer
  0 siblings, 1 reply; 8+ messages in thread
From: Akinori MUSHA @ 2001-07-03 11:16 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: zsh-workers

At Tue, 03 Jul 2001 11:49:02 +0100,
Oliver Kiddle wrote:
> First though, I've just tried to adapt it to also work for Linux. I
> also replaced your function with a substitution which I think should
> do the same thing so I would appreciate if you could check that the
> updated function below still works.

Thanks, I'm no zsh compdef hacker at all.  Please fix it as
appropriate.

> I don't suppose that $OSTYPE on FreeBSD includes any of the FreeBSD
> version. It is just that it is a tiny bit faster to check than
> `uname -sr`?

Oh, I didn't think of $OSTYPE.  On FreeBSD, its value looks like
"freebsd4.3" or "freebsd5.0" and on Linux it'd be "linux-gnu".

Why not use it then? :)

> If `sysctl -A' or `sysctl -aN' is run as a non-root user, do you get
> any output to stderr (you do on Linux)? If so, we need to add a
> redirection.

No, we don't get any stderr output on FreeBSD.

> Does anyone on zsh-workers mind if I put this on the stable branch.
> Mainly because I suspect the FreeBSD folks would otherwise be
> maintaining it as a patch for their port.

Indeed..  We'd appreciate seeing it in the stable releases.

Regards,

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Freeze this moment a little bit longer, make each impression
  a little bit stronger..  Experience slips away -- Time stand still"


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

* Re: a compdef for FreeBSD's sysctl(8) command
  2001-07-03 11:16   ` Akinori MUSHA
@ 2001-07-03 16:28     ` Bart Schaefer
  2001-07-03 18:27       ` Akinori MUSHA
  2001-07-04  8:46       ` Sven Wischnowsky
  0 siblings, 2 replies; 8+ messages in thread
From: Bart Schaefer @ 2001-07-03 16:28 UTC (permalink / raw)
  To: Akinori MUSHA, Oliver Kiddle; +Cc: zsh-workers

} Oliver Kiddle wrote:
} > Does anyone on zsh-workers mind if I put this on the stable branch.
} > Mainly because I suspect the FreeBSD folks would otherwise be
} > maintaining it as a patch for their port.

I don't object, but Sven has the final word for completion system stuff.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: a compdef for FreeBSD's sysctl(8) command
  2001-07-03 16:28     ` Bart Schaefer
@ 2001-07-03 18:27       ` Akinori MUSHA
  2001-07-04  8:46       ` Sven Wischnowsky
  1 sibling, 0 replies; 8+ messages in thread
From: Akinori MUSHA @ 2001-07-03 18:27 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Oliver Kiddle, zsh-workers

I found some bugs in the previous version and fixed.

Please use the attached one.

Regards,

-- 
                     /
                    /__  __            Akinori.org / MUSHA.org
                   / )  )  ) )  /     FreeBSD.org / Ruby-lang.org
Akinori MUSHA aka / (_ /  ( (__(  @ iDaemons.org / and.or.jp

"Freeze this moment a little bit longer, make each impression
  a little bit stronger..  Experience slips away -- Time stand still"

#compdef sysctl

case $OSTYPE in
  freebsd[0-4].*)
    _arguments -s \
      '-a[list all]' \
      '-A[show all opaques (values suppressed)]' \
      '-b[binary output]' \
      '-n[show only variable values]' \
      '-w[write mode]' \
      '-X[show all opaques (entire values)]' \
      '*:sysctl variable:compadd ${words[(r)-w]:+-S=} $(sysctl -A | sed "/^[^a-z]/d;s/:.*//")'
  ;;
  freebsd[5-9].*)
    _arguments -s \
      '-a[list all]' \
      '-b[binary output]' \
      '-N[show only variable names]' \
      '-n[show only variable values]' \
      '-o[show opaques as well (values suppressed)]' \
      '-x[show opaques as well (entire values)]' \
      '*:sysctl variable:compadd -S "" - $(sysctl -aN)'
  ;;
  linux*)
    _arguments -A "-*" \
      '-n[show only variable values]' \
      '(-n -p -a -A)-w[write mode]' \
      '(-n -w -a -A *)-p[specify file to load sysctl settings from]:file:_files' \
      '(-n -w -p -A *)-a[list all]' \
      '(-n -w -p -a *)-A[list all in table form]' \
      '(-n -p -a -A)*:sysctl variable:_files -W /proc/sys'
  ;;
esac


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

* Re: a compdef for FreeBSD's sysctl(8) command
  2001-07-03 16:28     ` Bart Schaefer
  2001-07-03 18:27       ` Akinori MUSHA
@ 2001-07-04  8:46       ` Sven Wischnowsky
  2001-07-05 11:04         ` PATCH: " Oliver Kiddle
  1 sibling, 1 reply; 8+ messages in thread
From: Sven Wischnowsky @ 2001-07-04  8:46 UTC (permalink / raw)
  To: zsh-workers

Bart Schaefer wrote:

> } Oliver Kiddle wrote:
> } > Does anyone on zsh-workers mind if I put this on the stable branch.
> } > Mainly because I suspect the FreeBSD folks would otherwise be
> } > maintaining it as a patch for their port.
> 
> I don't object, but Sven has the final word for completion system stuff.

I don't object either, new completion functions are seldom a problem (at
most they add problems where we didn't do anything sensible before).

I'm sure that I'm not the only one who would like to see exclusion lists
added for the BSD-parts, though, but that can be patched in later, of
course.


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* PATCH: Re: a compdef for FreeBSD's sysctl(8) command
  2001-07-04  8:46       ` Sven Wischnowsky
@ 2001-07-05 11:04         ` Oliver Kiddle
  0 siblings, 0 replies; 8+ messages in thread
From: Oliver Kiddle @ 2001-07-05 11:04 UTC (permalink / raw)
  To: zsh-workers; +Cc: Akinori MUSHA

Sven Wischnowsky wrote:

> I'm sure that I'm not the only one who would like to see exclusion lists
> added for the BSD-parts, though, but that can be patched in later, of
> course.

I carried on discussion of the sysctl completion with Akinori Musha off
the list and between us we have made a few improvements. The exclusion
lists are there and it also now uses _multi_parts for the variables.

One other issue was whether to cache the list of variables. For FreeBSD
4.x, it apparently takes quite a long time to generate the list because
sysctl -A extracts all the variables' values. The trouble is that the
list of variables changes if kernel modules are loaded/unloaded. As a
slightly crude solution, the patch below clears the cache in _kld - the
completion for kldload/kldunload. I think this is a reasonable way but
am not totally happy so I'd be interested if anyone else has any view on
this (and I won't commit the change just yet).

Oliver

Index: Completion/BSD/Command/_kld
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/BSD/Command/_kld,v
retrieving revision 1.1
diff -u -r1.1 _kld
--- Completion/BSD/Command/_kld	2001/04/02 12:21:07	1.1
+++ Completion/BSD/Command/_kld	2001/07/05 10:39:12
@@ -21,6 +21,8 @@
 }
 
 _kld() {
+  unset _cache_sysctlvars
+
   case "$service" in
   kldload)
     _arguments -s \
Index: Completion/Unix/Command/_sysctl
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_sysctl,v
retrieving revision 1.1
diff -u -r1.1 _sysctl
--- Completion/Unix/Command/_sysctl	2001/07/03 14:32:12	1.1
+++ Completion/Unix/Command/_sysctl	2001/07/05 10:39:12
@@ -1,25 +1,28 @@
 #compdef sysctl
 
 case $OSTYPE in
-  freebsd[0-4]*)
-    _arguments -s \
-      '-a[list all]' \
-      '-A[show all opaques (values suppressed)]' \
-      '-b[binary output]' \
-      '-n[show only variable values]' \
-      '-w[write mode]' \
-      '-X[show all opaques (entire values)]' \
-      "*:sysctl variable:compadd ${words[(r)-w]:+-S =} $(sysctl -A | sed 's/:.*//')"
+  freebsd[0-4].*)
+    : ${(A)_cache_sysctlvars:=${${$(sysctl -A):#[^a-z]*}%%:*}}
+    _arguments -s -A "-*" \
+      '(-w -X *)-a[list all]' \
+      '(-w -X *)-A[show all opaques (values suppressed)]' \
+      '(-w)-b[binary output]' \
+      '(-w)-n[show only variable values]' \
+      '(-a -A -b -n -X)-w[write mode]' \
+      '(-a -A -w *)-X[show all opaques (entire values)]' \
+      '(-a -A -X)*:sysctl variable:_multi_parts ${words[(r)-w]:+-S=} -i . _cache_sysctlvars'
   ;;
-  freebsd[5-9]*)
-    _arguments -s \
-      '-a[list all]' \
+  freebsd[5-9].*)
+    local -a sysctlvars
+    sysctlvars=( $(sysctl -aN) )
+    _arguments -s -A "-*" \
+      '(*)-a[list all]' \
       '-b[binary output]' \
-      '-N[show only variable names]' \
-      '-n[show only variable values]' \
-      '-o[show opaques as well (values suppressed)]' \
-      '-x[show opaques as well (entire values)]' \
-      '*:sysctl variable:compadd -S "" - $(sysctl -aN)'
+      '(-n)-N[show only variable names]' \
+      '(-N)-n[show only variable values]' \
+      '(-x)-o[show opaques as well (values suppressed)]' \
+      '(-o)-x[show opaques as well (entire values)]' \
+      '(-a)*:sysctl variable:_multi_parts -i . sysctlvars'
   ;;
   linux*)
     _arguments -A "-*" \

_____________________________________________________________________
This message has been checked for all known viruses by the 
MessageLabs Virus Scanning Service. For further information visit
http://www.messagelabs.com/stats.asp


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

end of thread, other threads:[~2001-07-05 11:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-03  5:52 a compdef for FreeBSD's sysctl(8) command Akinori MUSHA
2001-07-03  6:31 ` Andrej Borsenkow
2001-07-03 10:49 ` Oliver Kiddle
2001-07-03 11:16   ` Akinori MUSHA
2001-07-03 16:28     ` Bart Schaefer
2001-07-03 18:27       ` Akinori MUSHA
2001-07-04  8:46       ` Sven Wischnowsky
2001-07-05 11:04         ` PATCH: " Oliver Kiddle

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