initctl: minor refactor, simplify edit command

- Gamble a bit by redirecting stderr to /dev/null instead of command -v
- Drop vi from VISUAL/EDITOR expansion alternatives, tested later anyway

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-02-26 11:45:04 +01:00
parent 7439fa0c2a
commit 6cf8c7ade4
+14 -5
View File
@@ -202,6 +202,13 @@ int serv_touch(char *arg)
int serv_edit(char *arg)
{
char *editor[] = {
"sensible-editor",
"editor",
"${VISUAL:-${EDITOR}}",
"mg",
"vi"
};
char corr[40];
char path[256];
@@ -221,11 +228,13 @@ int serv_edit(char *arg)
if (!fexist(path))
return serv_list(NULL);
return !systemf("[ -x \"$(command -v sensible-editor)\" ] && sensible-editor %s", path) || \
!systemf("[ -x \"$(command -v editor)\" ] && editor %s", path) || \
!systemf("${VISUAL:-${EDITOR:-$(command -v vi)}} %s", path) || \
!systemf("[ -x \"$(command -v mg)\" ] && mg %s", path) || \
!systemf("[ -x \"$(command -v vi)\" ] && vi %s", path);
for (size_t i = 0; i < NELEMS(editor); i++) {
if (systemf("%s %s 2>/dev/null", editor[i], path))
continue;
return 0;
}
return 1;
}
/**