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.
This commit is contained in:
parent
202b18cdaa
commit
ca5fac557f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=71034
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user