diff options
author | des <des@FreeBSD.org> | 2001-01-14 16:40:06 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2001-01-14 16:40:06 +0000 |
commit | 993fa3797048e16be9d558df13d46df78af65f17 (patch) | |
tree | 9667887e550cdd9a53b3f7fdd5473167d2ebea27 /sbin | |
parent | fbfb6993c765f49169de81cc68b25bb3eaf2f785 (diff) | |
download | FreeBSD-src-993fa3797048e16be9d558df13d46df78af65f17.zip FreeBSD-src-993fa3797048e16be9d558df13d46df78af65f17.tar.gz |
Add a -N option that makes sysctl(8) print out just the variable names.
Zsh users can add the following to their .zshrc for sysctl completion:
function listsysctls {
case $1 in
*.*) set -A reply $(sysctl -AN ${1%.*}) ;;
*) set -A reply $(sysctl -AN) ;;
esac
}
compctl -K listsysctls sysctl
While I'm here, brucify the getopt() switch.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/sysctl/sysctl.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 959689a..c7c1234 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -58,7 +58,7 @@ static const char rcsid[] = #include <string.h> #include <unistd.h> -static int Aflag, aflag, bflag, nflag, wflag, Xflag; +static int Aflag, aflag, bflag, Nflag, nflag, wflag, Xflag; static int oidfmt(int *, int, char *, u_int *); static void parse(char *); @@ -86,21 +86,37 @@ main(int argc, char **argv) setbuf(stdout,0); setbuf(stderr,0); - while ((ch = getopt(argc, argv, "AabnwX")) != -1) { + while ((ch = getopt(argc, argv, "AabNnwX")) != -1) { switch (ch) { - case 'A': Aflag = 1; break; - case 'a': aflag = 1; break; - case 'b': bflag = 1; break; - case 'n': nflag = 1; break; - case 'w': wflag = 1; break; - case 'X': Xflag = Aflag = 1; break; - default: usage(); + case 'A': + Aflag = 1; + break; + case 'a': + aflag = 1; + break; + case 'b': + bflag = 1; + break; + case 'N': + Nflag = 1; + break; + case 'n': + nflag = 1; + break; + case 'w': + wflag = 1; + break; + case 'X': + Xflag = Aflag = 1; + break; + default: + usage(); } } argc -= optind; argv += optind; - if (wflag && (Aflag || aflag)) + if ((wflag && (Aflag || aflag)) || (Nflag && nflag)) usage(); if (Aflag || aflag) exit (sysctl_all(0, 0)); @@ -361,6 +377,11 @@ show_var(int *oid, int nlen) if (i || !j) err(1, "sysctl name %d %d %d", i, j, errno); + if (Nflag) { + printf("%s", name); + return (0); + } + /* find an estimate of how much we need for this var */ j = 0; i = sysctl(oid, nlen, 0, &j, 0, 0); |