[hackers] [wmii] Update selection and execution of wmiirc. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Mon, 28 Sep 2009 21:36:08 +0000 (UTC)

changeset: 2489:61132c90c0ae
user: Kris Maglione <jg_AT_suckless.org>
date: Mon Sep 28 17:24:01 2009 -0400
files: Makefile alternative_wmiircs/Makefile alternative_wmiircs/python/wmiirc cmd/Makefile cmd/wmii/_util.c cmd/wmii/fns.h cmd/wmii/main.c cmd/wmii/message.c
description:
Update selection and execution of wmiirc.

diff -r 7f49103fde51 -r 61132c90c0ae Makefile
--- a/Makefile Mon Sep 28 17:24:01 2009 -0400
+++ b/Makefile Mon Sep 28 17:24:01 2009 -0400
@@ -5,6 +5,7 @@
         cmd \
         libwmii_hack \
         rc \
+ alternative_wmiircs \
         man
 
 DIRS = \
diff -r 7f49103fde51 -r 61132c90c0ae alternative_wmiircs/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/alternative_wmiircs/Makefile Mon Sep 28 17:24:01 2009 -0400
@@ -0,0 +1,20 @@
+ROOT=..
+include $(ROOT)/mk/hdr.mk
+include $(ROOT)/mk/wmii.mk
+
+BIN = $(ETC)/wmii$(CONFVERSION)
+TARG = python \
+ plan9port
+
+$(TARG:%=%.install):
+ echo INSTALL $$($(CLEANNAME) $(BASE)${@:.install=})
+ cp -r ${@:.install=} $(DESTDIR)$(BIN)
+$(TARG:%=%.uninstall):
+ echo UNINSTALL $$($(CLEANNAME) $(BASE)${@:.uninstall=})
+ rm -rf $(DESTDIR)$(BIN)/${@:.uninstall=}
+
+.PHONY: $(TARG:%=%.install) $(TARG:%=%.uninstall)
+
+install: $(TARG:%=%.install)
+uninstall: $(TARG:%=%.uninstall)
+
diff -r 7f49103fde51 -r 61132c90c0ae alternative_wmiircs/python/wmiirc
--- a/alternative_wmiircs/python/wmiirc Mon Sep 28 17:24:01 2009 -0400
+++ b/alternative_wmiircs/python/wmiirc Mon Sep 28 17:24:01 2009 -0400
@@ -1,3 +1,7 @@
 #!/usr/bin/env python
+import os, sys
+for p in os.environ.get("WMII_CONFPATH", "").split(':'):
+ sys.path += [p, p + '/python']
+
 import pygmi
 import wmiirc
diff -r 7f49103fde51 -r 61132c90c0ae cmd/Makefile
--- a/cmd/Makefile Mon Sep 28 17:24:01 2009 -0400
+++ b/cmd/Makefile Mon Sep 28 17:24:01 2009 -0400
@@ -11,8 +11,7 @@
         wmii.sh \
         wmii9menu \
         wmii9rc \
- wmiir \
- wmiistartrc
+ wmiir
 
 OFILES = util.o
 
diff -r 7f49103fde51 -r 61132c90c0ae cmd/wmii/_util.c
--- a/cmd/wmii/_util.c Mon Sep 28 17:24:01 2009 -0400
+++ b/cmd/wmii/_util.c Mon Sep 28 17:24:01 2009 -0400
@@ -317,6 +317,31 @@
         return ret;
 }
 
+char*
+pathsearch(const char *path, const char *file, bool slashok) {
+ char *orig, *p, *s;
+
+ if(!slashok && strchr(file, '/') > file)
+ file = sxprint("%s/%s", getcwd(buffer, sizeof buffer), file);
+ else if(!strncmp(file, "./", 2))
+ file = sxprint("%s/%s", getcwd(buffer, sizeof buffer), file+2);
+ if(file[0] == '/') {
+ if(access(file, X_OK))
+ return strdup(file);
+ return nil;
+ }
+
+ orig = estrdup(path ? path : getenv("PATH"));
+ for(p=orig; (s=strtok(p, ":")); p=nil) {
+ s = smprint("%s/%s", s, file);
+ if(!access(s, X_OK))
+ break;
+ free(s);
+ }
+ free(orig);
+ return s;
+}
+
 int
 unquote(char *buf, char *toks[], int ntoks) {
         char *s, *t;
diff -r 7f49103fde51 -r 61132c90c0ae cmd/wmii/fns.h
--- a/cmd/wmii/fns.h Mon Sep 28 17:24:01 2009 -0400
+++ b/cmd/wmii/fns.h Mon Sep 28 17:24:01 2009 -0400
@@ -206,6 +206,7 @@
 
 /* main.c */
 void init_screens(void);
+void spawn_command(const char*);
 
 /* map.c */
 void** hash_get(Map*, const char*, bool create);
@@ -291,6 +292,7 @@
 int doublefork(void);
 void grep(char**, Reprog*, int);
 char* join(char**, char*);
+char* pathsearch(const char*, const char*, bool);
 void refree(Regex*);
 void reinit(Regex*, char*);
 int strlcatprint(char*, int, const char*, ...);
diff -r 7f49103fde51 -r 61132c90c0ae cmd/wmii/main.c
--- a/cmd/wmii/main.c Mon Sep 28 17:24:01 2009 -0400
+++ b/cmd/wmii/main.c Mon Sep 28 17:24:01 2009 -0400
@@ -95,6 +95,9 @@
                 setenv("WMII_ADDRESS", address, true);
         else
                 address = smprint("unix!%s/wmii", ns_path);
+ setenv("WMII_CONFPATH", sxprint("%s/.wmii%s:%s/wmii%s",
+ getenv("HOME"), CONFVERSION,
+ CONFPREFIX, CONFVERSION), true);
 }
 
 static void
@@ -281,18 +284,21 @@
         sigaction(SIGUSR2, &sa, nil);
 }
 
-static void
+void
 spawn_command(const char *cmd) {
         char *shell, *p;
 
+ if((p = pathsearch(getenv("WMII_CONFPATH"), cmd, true)))
+ cmd = p;
+
         if(doublefork() == 0) {
                 if(setsid() == -1)
                         fatal("Can't setsid: %r");
 
+ /* Run through the user's shell as a login shell */
                 shell = passwd->pw_shell;
                 if(shell[0] != '/')
                         fatal("Shell is not an absolute path: %s", shell);
- /* Run through the user's shell as a login shell */
                 p = smprint("-%s", strrchr(shell, '/') + 1);
 
                 close(0);
@@ -300,7 +306,7 @@
 
                 execl(shell, p, "-c", cmd, nil);
                 fatal("Can't exec '%s': %r", cmd);
- /* Not reached */
+ /* NOTREACHED */
         }
 }
 
@@ -332,7 +338,7 @@
 extern int fmtevent(Fmt*);
         fmtinstall('E', fmtevent);
 
- wmiirc = "wmiistartrc";
+ wmiirc = "wmiirc";
 
         oargv = argv;
         ARGBEGIN{
@@ -380,7 +386,7 @@
         closeexec(ConnectionNumber(display));
         closeexec(sock);
 
- if(wmiirc)
+ if(wmiirc[0])
                 spawn_command(wmiirc);
 
         init_traps();
diff -r 7f49103fde51 -r 61132c90c0ae cmd/wmii/message.c
--- a/cmd/wmii/message.c Mon Sep 28 17:24:01 2009 -0400
+++ b/cmd/wmii/message.c Mon Sep 28 17:24:01 2009 -0400
@@ -50,6 +50,7 @@
         LSELECT,
         LSEND,
         LSLAY,
+ LSPAWN,
         LSWAP,
         LTOGGLE,
         LUP,
@@ -83,6 +84,7 @@
         "select",
         "send",
         "slay",
+ "spawn",
         "swap",
         "toggle",
         "up",
@@ -502,6 +504,9 @@
                 execstr = strdup(m->pos);
                 srv.running = 0;
                 break;
+ case LSPAWN:
+ spawn_command(m->pos);
+ break;
         case LFOCUSCOLORS:
                 ret = msg_parsecolors(m, &def.focuscolor);
                 view_update(selview);
Received on Mon Sep 28 2009 - 21:36:08 UTC

This archive was generated by hypermail 2.2.0 : Mon Sep 28 2009 - 21:48:06 UTC