diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-11 14:38:51 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-11 14:38:51 +0100 |
| commit | b54f81925ef1dac55ad075e1b8b72e608aab269f (patch) | |
| tree | d65d1db37135748633c57b9c384d4d9a89befdf0 /vis.c | |
| parent | b3fb1e437f84138e5d6e8d9f6adbfce303b3a792 (diff) | |
| download | vis-b54f81925ef1dac55ad075e1b8b72e608aab269f.tar.gz vis-b54f81925ef1dac55ad075e1b8b72e608aab269f.tar.xz | |
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).
Diffstat (limited to 'vis.c')
| -rw-r--r-- | vis.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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); } |
