mirror of
https://github.com/troglobit/finit.git
synced 2026-11-02 13:20:32 +00:00
Added Edit command
Command Edit <CONF> opens file /etc/finit.d/available/<CONF>.conf in the editor referenced by Linux environment variable $EDITOR If $EDITOR is not set it will try to open emacs and if emacs is not found it will try to open the file in vim. Signed-off-by: Andreas Egeberg <andreas.egeberg@gmail.com>
This commit is contained in:
1 parent
fc82f0242c
commit
60d0ca1075
3 files changed
+34
No files matched your search
@@ -660,6 +660,7 @@ static int usage(int rc)
|
|||||||
" touch <CONF> Mark .conf in /etc/finit.d/ for reload\n"
|
" touch <CONF> Mark .conf in /etc/finit.d/ for reload\n"
|
||||||
" reload Reload *.conf in /etc/finit.d/ (activates changes)\n"
|
" reload Reload *.conf in /etc/finit.d/ (activates changes)\n"
|
||||||
// " reload <JOB|NAME>[:ID] Reload (SIGHUP) service by job# or name\n"
|
// " reload <JOB|NAME>[:ID] Reload (SIGHUP) service by job# or name\n"
|
||||||
|
" edit <CONF> Edit .conf in /etc/finit.d/available/\n"
|
||||||
"\n"
|
"\n"
|
||||||
" cond show Show condition status\n"
|
" cond show Show condition status\n"
|
||||||
" cond dump Dump all conditions and their status\n"
|
" cond dump Dump all conditions and their status\n"
|
||||||
@@ -709,6 +710,7 @@ int main(int argc, char *argv[])
|
|||||||
{ "enable", serv_enable },
|
{ "enable", serv_enable },
|
||||||
{ "disable", serv_disable },
|
{ "disable", serv_disable },
|
||||||
{ "touch", serv_touch },
|
{ "touch", serv_touch },
|
||||||
|
{ "edit", serv_edit },
|
||||||
{ "reload", do_reload },
|
{ "reload", do_reload },
|
||||||
|
|
||||||
{ "cond", do_cond },
|
{ "cond", do_cond },
|
||||||
|
|||||||
+31
@@ -27,6 +27,7 @@
|
|||||||
#include <fcntl.h> /* Definition of AT_* constants */
|
#include <fcntl.h> /* Definition of AT_* constants */
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <lite/lite.h>
|
#include <lite/lite.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -199,6 +200,36 @@ int serv_touch(char *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int serv_edit(char *arg)
|
||||||
|
{
|
||||||
|
char corr[40];
|
||||||
|
char path[256];
|
||||||
|
|
||||||
|
if (!arg || !arg[0])
|
||||||
|
return serv_list(NULL);
|
||||||
|
|
||||||
|
if (!strstr(arg, ".conf")) {
|
||||||
|
snprintf(corr, sizeof(corr), "%s.conf", arg);
|
||||||
|
arg = corr;
|
||||||
|
}
|
||||||
|
|
||||||
|
pushd(FINIT_RCSD);
|
||||||
|
if (mkdir("available", 0755) && EEXIST != errno)
|
||||||
|
err(1, "Failed creating %s/available directory", FINIT_RCSD);
|
||||||
|
|
||||||
|
snprintf(path, sizeof(path), "%s/%s", available, arg);
|
||||||
|
if (!fexist(path))
|
||||||
|
return serv_list(NULL);
|
||||||
|
|
||||||
|
if (systemf("[ -x \"$(command -v sensible-editor)\" ] && sensible-editor %s", path) != 0)
|
||||||
|
if (systemf("[ -x \"$(command -v editor)\" ] && editor %s", path) != 0)
|
||||||
|
if (systemf("${VISUAL:-${EDITOR:-$(command -v vi)}} %s", path) != 0)
|
||||||
|
if (systemf("[ -x \"$(command -v mg)\" ] && mg %s", path) != 0)
|
||||||
|
systemf("[ -x \"$(command -v vi)\" ] && vi %s", path);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ int serv_list (char *arg);
|
|||||||
int serv_enable (char *arg);
|
int serv_enable (char *arg);
|
||||||
int serv_disable (char *arg);
|
int serv_disable (char *arg);
|
||||||
int serv_touch (char *arg);
|
int serv_touch (char *arg);
|
||||||
|
int serv_edit (char *arg);
|
||||||
|
|
||||||
#endif /* FINIT_SERV_H_ */
|
#endif /* FINIT_SERV_H_ */
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user