sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit a7a79be3c204574c4bfae8eb441b3c6fe402a88f
parent 30083c563c17c69fc46d467248a24ff1dfebfc56
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date:   Wed,  7 Dec 2011 16:12:40 -0800

add my spawn_cwd patch for dwm 5.9.1
Diffstat:
Adwm.suckless.org/patches/dwm-5.9.1-spawn_cwd.diff | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adwm.suckless.org/patches/spawn_cwd.md | 16++++++++++++++++
2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/dwm.suckless.org/patches/dwm-5.9.1-spawn_cwd.diff b/dwm.suckless.org/patches/dwm-5.9.1-spawn_cwd.diff @@ -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 +@@ -20,6 +20,7 @@ + * + * To understand everything else, start reading main(). + */ ++#include <assert.h> + #include <errno.h> + #include <locale.h> + #include <stdarg.h> +@@ -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> +@@ -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 --git a/dwm.suckless.org/patches/spawn_cwd.md b/dwm.suckless.org/patches/spawn_cwd.md @@ -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@gmail.com>