From 149056033a6dc5deb0adc42f591517dcbe2d8a47 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 21 Sep 2019 21:14:59 -0700 Subject: Added support for default shell other than sh (e.g. dash, in case sh links to bash) --- Makefile | 4 ++++ bb.c | 8 ++++---- config.def.h | 8 ++++++-- 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 '}, "tput rmcup >/dev/tty; $SHELL; bb +r", "Open a "B("shell")}, {{'r', KEY_F2}, -- cgit v1.2.3