vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit d2083a6ec4a1b57fe45a42b69c23e5088054878c parent 35f4cc31685e478fcaacde5565c18fa9d498b99c Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 11 Nov 2016 14:38:51 +0100 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:
| M | vis-core.h | | | 1 | + |
| M | vis.c | | | 13 | +++++++++++-- |
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git 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 @@ -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); }