From b54f81925ef1dac55ad075e1b8b72e608aab269f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 11 Nov 2016 14:38:51 +0100 Subject: vis: attempt to use the default shell of the user to execute external commands We first try $SHELL and then fall back to the shell field of the password file entry (/etc/passwd). --- vis-core.h | 1 + vis.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/vis-core.h b/vis-core.h index 6940eaf..e16d23a 100644 --- a/vis-core.h +++ b/vis-core.h @@ -158,6 +158,7 @@ struct Vis { int tabwidth; /* how many spaces should be used to display a tab */ bool expandtab; /* whether typed tabs should be converted to spaces */ bool autoindent; /* whether indentation should be copied from previous line on newline */ + char *shell; /* shell used to launch external commands */ Map *cmds; /* ":"-commands, used for unique prefix queries */ Map *usercmds; /* user registered ":"-commands */ Map *options; /* ":set"-options */ diff --git a/vis.c b/vis.c index 6c92f6f..6782a8e 100644 --- a/vis.c +++ b/vis.c @@ -451,6 +451,14 @@ Vis *vis_new(Ui *ui, VisEvent *event) { goto err; if (!sam_init(vis)) goto err; + struct passwd *pw; + char *shell = getenv("SHELL"); + if ((!shell || !*shell) && (pw = getpwuid(getuid()))) + shell = pw->pw_shell; + if (!shell || !*shell) + shell = "/bin/sh"; + if (!(vis->shell = strdup(shell))) + goto err; vis->mode_prev = vis->mode = &vis_modes[VIS_MODE_NORMAL]; vis->event = event; if (event && event->vis_init) @@ -486,6 +494,7 @@ void vis_free(Vis *vis) { map_free(vis_modes[i].bindings); array_release_full(&vis->motions); array_release_full(&vis->textobjects); + free(vis->shell); free(vis); } @@ -1311,10 +1320,10 @@ int vis_pipe(Vis *vis, Filerange *range, bool interactive, const char *argv[], close(perr[0]); close(perr[1]); if (!argv[1]) - execl("/bin/sh", "sh", "-c", argv[0], NULL); + execlp(vis->shell, vis->shell, "-c", argv[0], (char*)NULL); else execvp(argv[0], (char* const*)argv); - vis_info_show(vis, "exec failure: %s", strerror(errno)); + fprintf(stderr, "exec failure: %s", strerror(errno)); exit(EXIT_FAILURE); } -- cgit v1.2.3