[wiki] [sites] add my spawn_cwd patch for dwm 5.9.1 || Suraj N. Kurapati

From: <hg_AT_suckless.org>
Date: Thu, 8 Dec 2011 01:12:45 +0100 (CET)

changeset: 801:16e5c1fcc50a
tag: tip
user: Suraj N. Kurapati <sunaku_AT_gmail.com>
date: Wed Dec 07 16:12:40 2011 -0800
files: dwm.suckless.org/patches/dwm-5.9.1-spawn_cwd.diff dwm.suckless.org/patches/spawn_cwd.md
description:
add my spawn_cwd patch for dwm 5.9.1


diff -r 34a245739e4b -r 16e5c1fcc50a dwm.suckless.org/patches/dwm-5.9.1-spawn_cwd.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwm.suckless.org/patches/dwm-5.9.1-spawn_cwd.diff Wed Dec 07 16:12:40 2011 -0800
_AT_@ -0,0 +1,69 @@
+https://github.com/sunaku/.dwm/compare/tip...spawn_cwd
+---
+diff --git a/dwm.c b/dwm.c
+index 1d78655..156ee60 100644
+--- a/dwm.c
++++ b/dwm.c
+_AT_@ -20,6 +20,7 @@
+ *
+ * To understand everything else, start reading main().
+ */
++#include <assert.h>
+ #include <errno.h>
+ #include <locale.h>
+ #include <stdarg.h>
+_AT_@ -28,6 +29,8 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <libgen.h>
++#include <sys/stat.h>
+ #include <sys/types.h>
+ #include <sys/wait.h>
+ #include <X11/cursorfont.h>
+_AT_@ -1661,11 +1664,45 @@ sigchld(int unused) {
+ while(0 < waitpid(-1, NULL, WNOHANG));
+ }
+
++#define SPAWN_CWD_DELIM " []{}()<>\"':"
++
+ void
+ spawn(const Arg *arg) {
+ if(fork() == 0) {
+ if(dpy)
+ close(ConnectionNumber(dpy));
++ if(selmon->sel) {
++ const char* const home = getenv("HOME");
++ assert(home && strchr(home, '/'));
++ const size_t homelen = strlen(home);
++ char *cwd, *pathbuf = NULL;
++ struct stat statbuf;
++
++ cwd = strtok(selmon->sel->name, SPAWN_CWD_DELIM);
++ /* NOTE: strtok() alters selmon->sel->name in-place,
++ * but that does not matter because we are going to
++ * exec() below anyway; nothing else will use it */
++ while(cwd) {
++ if(*cwd == '~') { /* replace ~ with $HOME */
++ if(!(pathbuf = malloc(homelen + strlen(cwd)))) /* ~ counts for NULL term */
++ die("fatal: could not malloc() %u bytes\n", homelen + strlen(cwd));
++ strcpy(strcpy(pathbuf, home) + homelen, cwd + 1);
++ cwd = pathbuf;
++ }
++
++ if(strchr(cwd, '/') && !stat(cwd, &statbuf)) {
++ if(!S_ISDIR(statbuf.st_mode))
++ cwd = dirname(cwd);
++
++ if(!chdir(cwd))
++ break;
++ }
++
++ cwd = strtok(NULL, SPAWN_CWD_DELIM);
++ }
++
++ free(pathbuf);
++ }
+ setsid();
+ execvp(((char **)arg->v)[0], (char **)arg->v);
+ fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]);
diff -r 34a245739e4b -r 16e5c1fcc50a dwm.suckless.org/patches/spawn_cwd.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwm.suckless.org/patches/spawn_cwd.md Wed Dec 07 16:12:40 2011 -0800
_AT_@ -0,0 +1,16 @@
+# spawn_cwd
+
+## Description
+
+Spawns programs from currently focused client's working directory. See this
+[blog post](http://snk.tuxfamily.org/log/dwm-spawn-cwd-patch.html) and this
+[announcement thread](http://thread.gmane.org/gmane.comp.misc.suckless/7959)
+for more information.
+
+## Download
+
+ * [spawn_cwd.diff](dwm-5.9.1-spawn_cwd.diff) spawn_cwd.diff (2011-11-25)
+
+## Author
+
+ * Suraj N. Kurapati - <sunaku_AT_gmail.com>
Received on Thu Dec 08 2011 - 01:12:45 CET

This archive was generated by hypermail 2.3.0 : Thu Sep 13 2012 - 19:31:53 CEST