aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-09-21 21:14:59 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-09-21 21:14:59 -0700
commit149056033a6dc5deb0adc42f591517dcbe2d8a47 (patch)
treea4556a097ef3952542f41065931741bb8f468ad0
parentca626182c1ba6573a81f55f5257fea9cb6800fb8 (diff)
Added support for default shell other than sh (e.g. dash, in case sh
links to bash)
-rw-r--r--Makefile4
-rw-r--r--bb.c8
-rw-r--r--config.def.h8
3 files changed, 14 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index ccc8cec..f834406 100644
--- a/Makefile
+++ b/Makefile
@@ -13,6 +13,10 @@ ifeq ($(shell uname),Darwin)
-Wno-missing-noreturn -Wno-cast-qual
endif
+ifneq (, $(SH))
+ CFLAGS += -D'SH="$(SH)"'
+endif
+
PICKER_FLAG=
ifeq (, $(PICKER))
PICKER=$(shell sh -c "(which fzy >/dev/null 2>/dev/null && echo 'fzy') || (which fzf >/dev/null 2>/dev/null && echo 'fzf') || (which pick >/dev/null 2>/dev/null && echo 'pick') || (which ask >/dev/null 2>/dev/null && echo 'ask')")
diff --git a/bb.c b/bb.c
index 587c983..fca4d3e 100644
--- a/bb.c
+++ b/bb.c
@@ -307,7 +307,7 @@ int run_script(bb_t *bb, const char *cmd)
size_t space = 32;
char **args = memcheck(calloc(space, sizeof(char*)));
size_t i = 0;
- args[i++] = "sh";
+ args[i++] = SH;
args[i++] = "-c";
char *fullcmd = calloc(strlen(cmd) + strlen(bbcmdfn) + 1, sizeof(char));
strcpy(fullcmd, bbcmdfn);
@@ -332,7 +332,7 @@ int run_script(bb_t *bb, const char *cmd)
ttyin = open("/dev/tty", O_RDONLY);
dup2(ttyout, STDOUT_FILENO);
dup2(ttyin, STDIN_FILENO);
- execvp("sh", args);
+ execvp(SH, args);
err("Failed to execute command: '%s'", cmd);
return -1;
}
@@ -1074,8 +1074,8 @@ bb_result_t process_cmd(bb_t *bb, const char *cmd)
} else {
close(fds[1]);
dup2(fds[0], STDIN_FILENO);
- char *args[] = {"sh", "-c", "$PAGER -rX", NULL};
- execvp("sh", args);
+ char *args[] = {SH, "-c", "$PAGER -rX", NULL};
+ execvp(SH, args);
}
init_term();
signal(SIGINT, old_handler);
diff --git a/config.def.h b/config.def.h
index e8d1d3e..498f03c 100644
--- a/config.def.h
+++ b/config.def.h
@@ -91,6 +91,10 @@ typedef struct {
#define DIR_COLOR "\033[34m"
#define EXECUTABLE_COLOR "\033[31m"
+#ifndef SH
+#define SH "sh"
+#endif
+
// Some handy macros for common shell script behaviors:
#define PAUSE " read -n1 -p '\033[2mPress any key to continue...\033[0m\033[?25l' >/dev/tty </dev/tty"
@@ -249,9 +253,9 @@ binding_t bindings[] = {
"{ if [ $type = File ]; then touch \"$name\"; else mkdir \"$name\"; fi "
"&& bb \"+goto:$name\" +r || "PAUSE"; }", B("New")" file/directory"},
{{'p'}, "$PAGER \"$@\"", B("Page")" through a file in $PAGER"},
- {{'|'}, ASK("cmd", "|", "") " && printf '%s\\n' \"$@\" | sh -c \"$BBSHELLFUNC$cmd\"; " PAUSE "; bb +r",
+ {{'|'}, ASK("cmd", "|", "") " && printf '%s\\n' \"$@\" | "SH" -c \"$BBSHELLFUNC$cmd\"; " PAUSE "; bb +r",
B("Pipe")" selected files to a command"},
- {{':'}, ASK("cmd", ":", "")" && sh -c \"$BBSHELLFUNC$cmd\" -- \"$@\"; " PAUSE "; bb +refresh",
+ {{':'}, ASK("cmd", ":", "")" && "SH" -c \"$BBSHELLFUNC$cmd\" -- \"$@\"; " PAUSE "; bb +refresh",
B("Run")" a command"},
{{'>'}, "tput rmcup >/dev/tty; $SHELL; bb +r", "Open a "B("shell")},
{{'r', KEY_F2},