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 <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-02-28 11:35:22 +01:00
parent 49582c70c5
commit 2ac39e1917
+17 -4
View File
@@ -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");
}