mirror of
https://github.com/troglobit/finit.git
synced 2026-10-08 16:34:45 +07:00
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:
+17
-4
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user