From a57b5f44dbc0f494639da67cf7acf8e156d6921f Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 18 Jun 2019 21:16:32 -0700 Subject: [PATCH] Removed all the /dev/tty redirection and just dup2()'d it before exec()ing the user scripts --- bb.c | 5 +++++ config.def.h | 29 ++++++++++++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/bb.c b/bb.c index 47a4bbf..a2dd99f 100644 --- a/bb.c +++ b/bb.c @@ -291,6 +291,11 @@ int run_script(bb_t *bb, const char *cmd) setenv("BBDOTFILES", bb->show_dotfiles ? "1" : "", 1); setenv("BBCURSOR", bb->nfiles ? bb->files[bb->cursor]->fullname : "", 1); + int ttyout, ttyin; + ttyout = open("/dev/tty", O_RDWR); + ttyin = open("/dev/tty", O_RDONLY); + dup2(ttyout, STDOUT_FILENO); + dup2(ttyin, STDIN_FILENO); execvp("sh", args); err("Failed to execute command: '%s'", cmd); return -1; diff --git a/config.def.h b/config.def.h index 3629a70..14b6460 100644 --- a/config.def.h +++ b/config.def.h @@ -164,17 +164,11 @@ const char *startupcmds[] = { * Please note that these are sh scripts, not bash scripts, so bash-isms * won't work unless you make your script use `bash -c ""` * - * All output should be redirected to /dev/tty, otherwise cd "$(bb -d)" will - * break because stdout will be polluted with all the keybindings that spammed - * stdout. Similarly, user input should be pulled from /dev/tty so anything - * piped into bb won't be misinterpreted as user input. - * * If your editor is vim (and not neovim), you can replace `$EDITOR` below with * `vim -c 'set t_ti= t_te=' "$@"` to prevent momentarily seeing the shell * after editing. *****************************************************************************/ binding_t bindings[] = { - {{'1'}, "echo \"you said: '$(sed 1q /dev/tty; "PAUSE, "repeat"}, {{'?', KEY_F1}, "bb -b | $PAGER -rX", B("Help")" menu"}, {{'q', 'Q'}, "+quit", B("Quit")}, {{'j', KEY_ARROW_DOWN}, "+move:+1", B("Next")" file"}, @@ -184,11 +178,12 @@ binding_t bindings[] = { {{'\r', KEY_MOUSE_DOUBLE_LEFT}, #ifdef __APPLE__ "if test -d \"$BBCURSOR\"; then bb \"+cd:$BBCURSOR\"; " - "elif test -x \"$BBCURSOR\"; then \"$BBCURSOR\" >/dev/tty /dev/tty /dev/tty /dev/tty /dev/tty /dev/tty /dev/tty; " PAUSE "; bb +r", + {{'|'}, ASK("cmd", "|", "") " && printf '%s\\n' \"$@\" | sh -c \"$cmd\"; " PAUSE "; bb +r", B("Pipe")" selected files to a command"}, - {{':'}, "sh -c \"$(" ASKECHO(":", "") ")\" -- \"$@\" >/dev/tty '}, "tput rmcup >/dev/tty; $SHELL; bb +r", "Open a "B("shell")}, - {{'m'}, "read -n1 -p 'Mark: ' m >/dev/tty /dev/tty '}, "tput rmcup; $SHELL; bb +r", "Open a "B("shell")}, + {{'m'}, "read -n1 -p 'Mark: ' m && bb \"+mark:$m;$PWD\"", "Set "B("mark")}, + {{'\''}, "read -n1 -p 'Jump: ' j && bb \"+jump:$j\"", B("Jump")" to mark"}, {{'r'}, "bb +refresh; " "for f; do "