commit 807917d960210409f31c02d82b950af1eea2f95c
parent 980c53eb435023fca0137328ba15733a7833463e
Author: Bastien Dejean <nihilhill@gmail.com>
Date: Mon, 7 Jan 2013 11:15:26 +0100
Support alternative shell definition
Diffstat:
5 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/README.md b/README.md
@@ -38,7 +38,9 @@ Mouse hotkeys can be defined by using one of the following special keysym names:
In addition, the sequences can contain ranges of the form `A-Z` where *A* and *Z* are alphanumeric characters.
-What is actually executed is `/bin/sh -c COMMAND`, which means you can use environment variables in `COMMAND`.
+What is actually executed is `SHELL -c COMMAND`, which means you can use environment variables in `COMMAND`.
+
+`SHELL` will be the content of the first defined environment variable in the following list: `SXHKD_SHELL`, `SHELL`.
If *sxhkd* receives a `SIGUSR1` signal, it will reload its configuration file.
diff --git a/helpers.h b/helpers.h
@@ -2,7 +2,6 @@
#define _HELPERS_H
#define LENGTH(x) (sizeof(x) / sizeof(*x))
-#define SHELL "/bin/sh"
#define MAXLEN 256
#ifdef DEBUG
diff --git a/sxhkd.1 b/sxhkd.1
@@ -41,7 +41,7 @@ General Syntax:
Where
.I MODIFIER
is one of the following names:
-.IR super , " hyper", " meta", " alt", " control", " ctrl", " shift", " mode_switch", " lock", " mod1", " mod2", " mod3", " mod4", " mod5" .
+.BR super , " hyper", " meta", " alt", " control", " ctrl", " shift", " mode_switch", " lock", " mod1", " mod2", " mod3", " mod4", " mod5" .
.PP
If
.I @
@@ -52,7 +52,7 @@ The keysym names are those your will get from
(minus the prefix if any).
.PP
Mouse hotkeys can be defined by using one of the following special keysym names:
-.IR button1 ", " button2 ", " button3 ", ..., " button24 .
+.BR button1 ", " button2 ", " button3 ", ..., " button24 .
.PP
.I KEYSYM
can contain a sequence of the form
@@ -72,10 +72,15 @@ where
are alphanumeric characters.
.PP
What is actually executed is
-.IR "/bin/sh -c COMMAND" ,
+.IB SHELL " -c "
+.IR COMMAND ,
which means you can use environment variables in
.IR COMMAND .
.PP
+.I SHELL
+will be the content of the first defined environment variable in the following list:
+.BR SXHKD_SHELL ", " SHELL .
+.PP
If
.B sxhkd
receives a
@@ -83,7 +88,7 @@ receives a
signal, it will reload its configuration file.
.PP
If no configuration file is specified through the
-.I -c
+.B -c
option, the following is used:
.IR $XDG_CONFIG_HOME/sxhkd/sxhkdrc .
.SH AUTHOR
diff --git a/sxhkd.c b/sxhkd.c
@@ -36,6 +36,8 @@ void setup(void)
/* if (reply == NULL) */
/* warn("couldn't set detectable auto repeat\n"); */
/* free(reply); */
+ if ((shell = getenv(SXHKD_SHELL_ENV)) == NULL && (shell = getenv(SHELL_ENV)) == NULL)
+ err("The '%s' environment variable is not defined.\n", SHELL_ENV);
symbols = xcb_key_symbols_alloc(dpy);
hotkeys = NULL;
}
@@ -173,7 +175,7 @@ void key_button_event(xcb_generic_event_t *evt, xcb_event_mask_t event_mask)
if (keysym != XCB_NO_SYMBOL || button != XCB_NONE) {
hotkey_t *hk = find_hotkey(keysym, button, modfield, event_mask);
if (hk != NULL) {
- char *cmd[] = {SHELL, "-c", hk->command, NULL};
+ char *cmd[] = {shell, "-c", hk->command, NULL};
spawn(cmd);
}
}
diff --git a/sxhkd.h b/sxhkd.h
@@ -7,6 +7,8 @@
#include "helpers.h"
#define CONFIG_HOME_ENV "XDG_CONFIG_HOME"
+#define SXHKD_SHELL_ENV "SXHKD_SHELL"
+#define SHELL_ENV "SHELL"
#define CONFIG_PATH "sxhkd/sxhkdrc"
#define TOK_SEP "+ \n"
#define NUM_MOD 8
@@ -29,6 +31,7 @@ typedef struct {
xcb_connection_t *dpy;
xcb_window_t root;
xcb_key_symbols_t *symbols;
+char *shell;
hotkey_t *hotkeys;
char config_file[MAXLEN];