mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
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:
1 parent
7439fa0c2a
commit
6cf8c7ade4
1 file changed
+14
-5
+14
-5
@@ -202,6 +202,13 @@ int serv_touch(char *arg)
|
|||||||
|
|
||||||
int serv_edit(char *arg)
|
int serv_edit(char *arg)
|
||||||
{
|
{
|
||||||
|
char *editor[] = {
|
||||||
|
"sensible-editor",
|
||||||
|
"editor",
|
||||||
|
"${VISUAL:-${EDITOR}}",
|
||||||
|
"mg",
|
||||||
|
"vi"
|
||||||
|
};
|
||||||
char corr[40];
|
char corr[40];
|
||||||
char path[256];
|
char path[256];
|
||||||
|
|
||||||
@@ -221,11 +228,13 @@ int serv_edit(char *arg)
|
|||||||
if (!fexist(path))
|
if (!fexist(path))
|
||||||
return serv_list(NULL);
|
return serv_list(NULL);
|
||||||
|
|
||||||
return !systemf("[ -x \"$(command -v sensible-editor)\" ] && sensible-editor %s", path) || \
|
for (size_t i = 0; i < NELEMS(editor); i++) {
|
||||||
!systemf("[ -x \"$(command -v editor)\" ] && editor %s", path) || \
|
if (systemf("%s %s 2>/dev/null", editor[i], path))
|
||||||
!systemf("${VISUAL:-${EDITOR:-$(command -v vi)}} %s", path) || \
|
continue;
|
||||||
!systemf("[ -x \"$(command -v mg)\" ] && mg %s", path) || \
|
return 0;
|
||||||
!systemf("[ -x \"$(command -v vi)\" ] && vi %s", path);
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user