From 2ac39e19174f24f13e18ce8bba377440b108e8fd Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 28 Feb 2021 11:34:36 +0100 Subject: [PATCH] initctl: restore Andreas' clever $(command ...) eval, it works Turns out that on some systems, that has none of the first two, and neither of the two environment variables set in ${VISUAL:-${EDITOR}}, they evaluate to 'sh /etc/finit.d/file.conf', which is true, so we wouldn't even try mg or vi ... This patch reverts to the spirit of Andreas Egebergs initial commit, which turns out to be a better solution anyway :) Signed-off-by: Joachim Wiberg --- src/serv.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/serv.c b/src/serv.c index 2281b9ec..36ff45ea 100644 --- a/src/serv.c +++ b/src/serv.c @@ -244,14 +244,27 @@ int serv_touch(char *arg) return 0; } +/* + * Try to open an editor for the given file, if creat is given we + * create a new file based on /lib/finit/sample.conf + * + * The order of editors that this command checks for is evaluated + * as follows, in order: + * + * sensible-editor :: debian based systems + * editor :: debian + most other systems + * VISUAL :: full-screen editor program + * EDITOR :: line-mode editor program + * $(command ...) :: fallback to mg or vi + * + * For details: https://jdebp.uk/FGA/unix-editors-and-pagers.html + */ static int do_edit(char *arg, int creat) { char *editor[] = { "sensible-editor", "editor", - "${VISUAL:-${EDITOR}}", - "mg", - "vi" + "${VISUAL:-${EDITOR:$(command -v mg vi | head -1)}}" }; char path[256]; char *fn; @@ -259,7 +272,7 @@ static int do_edit(char *arg, int creat) fn = conf(path, sizeof(path), arg, creat); if (!fexist(fn)) { if (!creat) { - warnx("Cannot find %s, use create command, or select one of:", arg); + warnx("Cannot find %s, use -c flag, create command, or select one of:", arg); return serv_list("available"); }