changeset: 2677:49c7824cf9b0
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Sun May 30 15:18:15 2010 -0400
files: cmd/wmii.rc.rc cmd/wmii.sh.sh cmd/wmiir.c man/wmiir.1 man/wmiir.man1
description:
Give up on implementing proglist portably in sh and do it in C. Fixes issue #42.
diff -r 66e953f9c6b4 -r 49c7824cf9b0 cmd/wmii.rc.rc
--- a/cmd/wmii.rc.rc Sun May 30 11:28:06 2010 -0400
+++ b/cmd/wmii.rc.rc Sun May 30 15:18:15 2010 -0400
@@ -58,10 +58,7 @@
}
fn wi_proglist {
- # XXX: maxdepth is not POSIX compliant.
- ifs=: { find -L `{echo -n $*} -type f -a -maxdepth 1 \
- '(' -perm -0100 -o -perm -0010 -o -perm -0001 ')' >[2]/dev/null \
- | sed 's,.*/,,' | sort | uniq}
+ ifs=: { wmiir proglist -- `{echo -n $*} | sort | uniq }
}
fn wi_actions {
diff -r 66e953f9c6b4 -r 49c7824cf9b0 cmd/wmii.sh.sh
--- a/cmd/wmii.sh.sh Sun May 30 11:28:06 2010 -0400
+++ b/cmd/wmii.sh.sh Sun May 30 15:18:15 2010 -0400
@@ -135,9 +135,7 @@
}
wi_proglist() {
- ls -lL $(echo $* | sed 'y/:/ /') 2>/dev/null \
- | awk '$1 ~ /^[^d].*x/ { print $NF }' \
- | sort | uniq
+ wmiir proglist -- $(echo $* | sed 'y/:/ /') | sort | uniq
}
wi_actions() {
diff -r 66e953f9c6b4 -r 49c7824cf9b0 cmd/wmiir.c
--- a/cmd/wmiir.c Sun May 30 11:28:06 2010 -0400
+++ b/cmd/wmiir.c Sun May 30 15:18:15 2010 -0400
@@ -3,6 +3,7 @@
*/
#define IXP_NO_P9_
#define IXP_P9_STRUCTS
+#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <sys/signal.h>
@@ -329,14 +330,43 @@
}
static int
+xproglist(int argc, char *argv[]) {
+ DIR *d;
+ struct dirent *de;
+ char *dir;
+
+ quotefmtinstall();
+
+ ARGBEGIN{
+ default:
+ usage();
+ }ARGEND;
+
+ while((dir = ARGF()))
+ if((d = opendir(dir))) {
+ while((de = readdir(d)))
+ if(access(de->d_name, X_OK))
+ print("%q\n", de->d_name);
+ closedir(d);
+ }
+
+ return 0; /* NOTREACHED */
+}
+
+static int
xsetsid(int argc, char *argv[]) {
char *av0;
+ bool dofork;
av0 = nil;
+ dofork = false;
ARGBEGIN{
case '0':
av0 = EARGF(usage());
break;
+ case 'f':
+ dofork = true;
+ break;
default:
usage();
}ARGEND;
@@ -346,6 +376,13 @@
return 1;
setsid();
+ if(dofork)
+ switch(fork()) {
+ case 0: break;
+ case -1: fatal("can't fork: %r\n");
+ default: return 0;
+ }
+
execvp(av0, argv);
fatal("setsid: can't exec: %r");
return 1; /* NOTREACHED */
@@ -368,6 +405,7 @@
}, utiltab[] = {
{"namespace", xnamespace},
{"ns", xnamespace},
+ {"proglist", xproglist},
{"setsid", xsetsid},
{0, }
};
diff -r 66e953f9c6b4 -r 49c7824cf9b0 man/wmiir.1
--- a/man/wmiir.1 Sun May 30 11:28:06 2010 -0400
+++ b/man/wmiir.1 Sun May 30 15:18:15 2010 -0400
@@ -25,6 +25,9 @@
The address at which to connect to \fBwmii\fR.
.SH COMMANDS
+.P
+The following commands deal with 9P filesystems.
+
.TP
create \fI<file>\fR
Creates a new file or directory in the filesystem. Permissions and
@@ -57,7 +60,7 @@
remove \fI<path>\fR
Removes \fI<path>\fR from the filesystem.
-Synonyms: rm
+Synonyms: \fBrm\fR
.TP
write \fI<file>\fR
Writes the contents of the standard input to \fI<file>\fR.
@@ -66,6 +69,48 @@
Writes each argument after \fI<file>\fR to the latter.
+.P
+Additionally, wmiir provides the following utility commands relevant
+to scripting wmii:
+
+.TP
+namespace
+
+.RS
+Prints the current wmii namespace directory, usually
+equivalent to /tmp/ns.\fB$USER\fR.\fB${DISPLAY\fR%.0\fB}\fR, but possibly
+different depending on the value of \fB$NAMESPACE\fR and
+\fB$WMII_NAMESPACE\fR.
+.RE
+
+.RS
+Synonyms: \fBns\fR
+.RE
+.TP
+setsid \fI[\-0 \fI<argv0>\fR]\fR \fI[\-f]\fR \fI<command>\fR
+
+.RS
+Executes the given command after setting the session id (see
+setsid(2)). If \fI\-0\fR is given, the command is run with the
+given value as argv\fI[0]\fR. For instance, to run sh as a login
+shell, one might run
+.RE
+
+.nf
+ wmiir setsid -0 -sh sh
+.fi
+
+.RS
+If \fI\-f\fR is given, wmiir will fork into the background before
+executing the command.
+.RE
+.TP
+proglist \fI[\-\-]\fR \fI<directory>\fR ...
+
+.RS
+Lists all executable commands in the given directories.
+.RE
+
.SH ENVIRONMENT
.TP
\fB$WMII_ADDRESS\fR
diff -r 66e953f9c6b4 -r 49c7824cf9b0 man/wmiir.man1
--- a/man/wmiir.man1 Sun May 30 11:28:06 2010 -0400
+++ b/man/wmiir.man1 Sun May 30 15:18:15 2010 -0400
@@ -28,6 +28,8 @@
:
= COMMANDS =
+The following commands deal with 9P filesystems.
+
: create <file>
Creates a new file or directory in the filesystem. Permissions and
file type are inferred by `wmii`. The contents of the standard input
@@ -53,13 +55,35 @@
: remove <path>
Removes <path> from the filesystem.
- Synonyms: rm
+ Synonyms: `rm`
: write <file>
Writes the contents of the standard input to <file>.
: xwrite <file> <data> ...
Writes each argument after <file> to the latter.
:
+Additionally, wmiir provides the following utility commands relevant
+to scripting wmii:
+
+: namespace
+ Prints the current wmii namespace directory, usually
+ equivalent to /tmp/ns.$USER.${DISPLAY%.0}, but possibly
+ different depending on the value of $NAMESPACE and
+ $WMII_NAMESPACE.
+
+ Synonyms: `ns`
+: setsid [-0 <argv0>] [-f] <command>
+ Executes the given command after setting the session id (see
+ setsid(2)). If _-0_ is given, the command is run with the
+ given value as argv[0]. For instance, to run sh as a login
+ shell, one might run
+
+``` wmiir setsid -0 -sh sh
+ If _-f_ is given, wmiir will fork into the background before
+ executing the command.
+: proglist [--] <directory> ...
+ Lists all executable commands in the given directories.
+
= ENVIRONMENT =
: $WMII_ADDRESS
Received on Sun May 30 2010 - 19:18:33 UTC
This archive was generated by hypermail 2.2.0 : Sun May 30 2010 - 19:24:05 UTC