forked from speedie/spmenu
allow specifying a specific configuration file to load
This commit is contained in:
parent
5eb54af7a6
commit
68b58325d4
|
@ -278,11 +278,15 @@ You may use long, descriptive arguments or the shorter arguments.
|
||||||
`-nwm, --unmanaged`
|
`-nwm, --unmanaged`
|
||||||
: Don't spawn spmenu as a window manager controlled client/window. Useful for testing
|
: Don't spawn spmenu as a window manager controlled client/window. Useful for testing
|
||||||
|
|
||||||
|
`-cf, --config-file file`
|
||||||
|
: Set config file to load to file
|
||||||
|
|
||||||
`-lcfg, --load-config`
|
`-lcfg, --load-config`
|
||||||
: Load spmenu configuration (~/.spmenu or ~/.config/spmenu/spmenurc)
|
: Load spmenu configuration (~/.config/spmenu/spmenu.conf, ~/.spmenurc or ~/.config/spmenu/spmenurc)
|
||||||
|
|
||||||
`-ncfg, --no-load-config`
|
`-ncfg, --no-load-config`
|
||||||
: Don't load spmenu configuration (~/.spmenu or ~/.config/spmenu/spmenurc)
|
: Don't load spmenu configuration (~/.config/spmenu/spmenu.conf, ~/.spmenurc
|
||||||
|
or ~/.config/spmenu/spmenurc)
|
||||||
|
|
||||||
`-v, --version`
|
`-v, --version`
|
||||||
: Print spmenu version to stdout
|
: Print spmenu version to stdout
|
||||||
|
|
28
libs/argv.c
28
libs/argv.c
|
@ -4,7 +4,7 @@ readargs(int argc, char *argv[])
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
|
||||||
int cxrdb = 0;
|
int profilecmd = 0;
|
||||||
|
|
||||||
// check if we should load the xrdb/config, because it needs to be loaded before arguments are checked
|
// check if we should load the xrdb/config, because it needs to be loaded before arguments are checked
|
||||||
// priority: internal -> config -> xresources -> arguments
|
// priority: internal -> config -> xresources -> arguments
|
||||||
|
@ -21,6 +21,13 @@ readargs(int argc, char *argv[])
|
||||||
globalcolors = 1;
|
globalcolors = 1;
|
||||||
} else if (!strcmp(argv[j], "-ngbc") || (!strcmp(argv[j], "--no-global-colors"))) {
|
} else if (!strcmp(argv[j], "-ngbc") || (!strcmp(argv[j], "--no-global-colors"))) {
|
||||||
globalcolors = 0;
|
globalcolors = 0;
|
||||||
|
} else if (!strcmp(argv[j], "-cf") || (!strcmp(argv[j], "--config-file"))) { // specify a config file
|
||||||
|
if (argv[j+1]) {
|
||||||
|
cconf = 1;
|
||||||
|
argconf = argv[++j];
|
||||||
|
} else {
|
||||||
|
die("This argument requires a second argument.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,10 +41,10 @@ readargs(int argc, char *argv[])
|
||||||
|
|
||||||
// also load config/profile if .Xresources
|
// also load config/profile if .Xresources
|
||||||
if (loadconfig) {
|
if (loadconfig) {
|
||||||
cxrdb = system("command -v spmenu_profile > /dev/null && spmenu_profile --spmenu-load-default-profile > /dev/null");
|
profilecmd = system("command -v spmenu_profile > /dev/null && spmenu_profile --spmenu-load-default-profile > /dev/null");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cxrdb||cxrdb) // load .Xresources, cxrdb is only here to avoid an annoying gcc warning
|
if (!profilecmd||profilecmd) // load .Xresources, profilecmd is only here to avoid an annoying gcc warning
|
||||||
load_xresources();
|
load_xresources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +177,9 @@ readargs(int argc, char *argv[])
|
||||||
|| !strcmp(argv[i], "-ngbc")
|
|| !strcmp(argv[i], "-ngbc")
|
||||||
|| !strcmp(argv[i], "--global-colors")
|
|| !strcmp(argv[i], "--global-colors")
|
||||||
|| !strcmp(argv[i], "--no-global-colors")
|
|| !strcmp(argv[i], "--no-global-colors")
|
||||||
|
|| !strcmp(argv[i], "-cf")
|
||||||
|
|| !strcmp(argv[i], "--config-file")
|
||||||
|
|| !strcmp(argv[i], argconf)
|
||||||
))
|
))
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
|
@ -350,6 +360,13 @@ readargs(int argc, char *argv[])
|
||||||
|| !strcmp(argv[i], "-ncfg")
|
|| !strcmp(argv[i], "-ncfg")
|
||||||
|| !strcmp(argv[i], "--load-config")
|
|| !strcmp(argv[i], "--load-config")
|
||||||
|| !strcmp(argv[i], "--no-load-config")
|
|| !strcmp(argv[i], "--no-load-config")
|
||||||
|
|| !strcmp(argv[i], "-gbc")
|
||||||
|
|| !strcmp(argv[i], "-ngbc")
|
||||||
|
|| !strcmp(argv[i], "--global-colors")
|
||||||
|
|| !strcmp(argv[i], "--no-global-colors")
|
||||||
|
|| !strcmp(argv[i], "-cf")
|
||||||
|
|| !strcmp(argv[i], "--config-file")
|
||||||
|
|| !strcmp(argv[i], argconf)
|
||||||
))
|
))
|
||||||
continue;
|
continue;
|
||||||
else
|
else
|
||||||
|
@ -460,8 +477,9 @@ usage(void)
|
||||||
"spmenu -itc, --image-topcenter Position the image in the top center\n"
|
"spmenu -itc, --image-topcenter Position the image in the top center\n"
|
||||||
"spmenu -wm, --managed, --x11-client Spawn spmenu as a window manager controlled client/window. Useful for testing\n"
|
"spmenu -wm, --managed, --x11-client Spawn spmenu as a window manager controlled client/window. Useful for testing\n"
|
||||||
"spmenu -nwm, --unmanaged Don't spawn spmenu as a window manager controlled client/window. Useful for testing\n"
|
"spmenu -nwm, --unmanaged Don't spawn spmenu as a window manager controlled client/window. Useful for testing\n"
|
||||||
"spmenu -lcfg, --load-config Load spmenu configuration (~/.spmenu or ~/.config/spmenu/spmenurc)\n"
|
"spmenu -cf, --config-file <file> Set config file to load to <file>\n"
|
||||||
"spmenu -ncfg, --no-load-config Don't load spmenu configuration (~/.spmenu or ~/.config/spmenu/spmenurc)\n"
|
"spmenu -lcfg, --load-config Load spmenu configuration (~/.config/spmenu/spmenu.conf, ~/.spmenu or ~/.config/spmenu/spmenurc)\n"
|
||||||
|
"spmenu -ncfg, --no-load-config Don't load spmenu configuration (~/.config/spmenu/spmenu.conf, ~/.spmenu or ~/.config/spmenu/spmenurc)\n"
|
||||||
"spmenu -v, --version Print spmenu version to stdout\n"
|
"spmenu -v, --version Print spmenu version to stdout\n"
|
||||||
"\n", stdout);
|
"\n", stdout);
|
||||||
|
|
||||||
|
|
|
@ -12,24 +12,32 @@ conf_init(void)
|
||||||
if (!loadconfig) return;
|
if (!loadconfig) return;
|
||||||
|
|
||||||
// get path for configuration file
|
// get path for configuration file
|
||||||
if (!(xdg_conf = getenv("XDG_CONFIG_HOME"))) {
|
if (!cconf || !argconf) {
|
||||||
// ~/.config/spmenu/spmenu.conf
|
if (!(xdg_conf = getenv("XDG_CONFIG_HOME"))) {
|
||||||
home = getenv("HOME");
|
// ~/.config/spmenu/spmenu.conf
|
||||||
|
home = getenv("HOME");
|
||||||
|
|
||||||
// malloc
|
// malloc
|
||||||
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s/%s", home, ".config/spmenu/spmenu.conf") + 1))) {
|
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s/%s", home, ".config/spmenu/spmenu.conf") + 1))) {
|
||||||
die("spmenu: failed to malloc cfgfile");
|
die("spmenu: failed to malloc cfgfile");
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(cfgfile, "%s/%s", home, ".config/spmenu/spmenu.conf");
|
||||||
|
} else {
|
||||||
|
// malloc
|
||||||
|
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s/%s", xdg_conf, "spmenu/spmenu.conf") + 1))) {
|
||||||
|
die("spmenu: failed to malloc cfgfile");
|
||||||
|
}
|
||||||
|
|
||||||
|
// XDG_CONFIG_HOME is set, so let's use that instead
|
||||||
|
sprintf(cfgfile, "%s/%s", xdg_conf, "spmenu/spmenu.conf");
|
||||||
}
|
}
|
||||||
|
} else { // custom config path
|
||||||
|
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s", argconf) + 1))) {
|
||||||
|
die("spmenu: failed to malloc cfgfile");
|
||||||
|
}
|
||||||
|
|
||||||
sprintf(cfgfile, "%s/%s", home, ".config/spmenu/spmenu.conf");
|
sprintf(cfgfile, "%s", argconf);
|
||||||
} else {
|
|
||||||
// malloc
|
|
||||||
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s/%s", xdg_conf, "spmenu/spmenu.conf") + 1))) {
|
|
||||||
die("spmenu: failed to malloc cfgfile");
|
|
||||||
}
|
|
||||||
|
|
||||||
// XDG_CONFIG_HOME is set, so let's use that instead
|
|
||||||
sprintf(cfgfile, "%s/%s", xdg_conf, "spmenu/spmenu.conf");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't bother trying to load if it doesn't exist.
|
// don't bother trying to load if it doesn't exist.
|
||||||
|
|
11
spmenu.1
11
spmenu.1
|
@ -298,13 +298,16 @@ Useful for testing
|
||||||
Don\[cq]t spawn spmenu as a window manager controlled client/window.
|
Don\[cq]t spawn spmenu as a window manager controlled client/window.
|
||||||
Useful for testing
|
Useful for testing
|
||||||
.TP
|
.TP
|
||||||
|
\f[V]-cf, --config-file file\f[R]
|
||||||
|
Set config file to load to file
|
||||||
|
.TP
|
||||||
\f[V]-lcfg, --load-config\f[R]
|
\f[V]-lcfg, --load-config\f[R]
|
||||||
Load spmenu configuration (\[ti]/.spmenu or
|
Load spmenu configuration (\[ti]/.config/spmenu/spmenu.conf,
|
||||||
\[ti]/.config/spmenu/spmenurc)
|
\[ti]/.spmenurc or \[ti]/.config/spmenu/spmenurc)
|
||||||
.TP
|
.TP
|
||||||
\f[V]-ncfg, --no-load-config\f[R]
|
\f[V]-ncfg, --no-load-config\f[R]
|
||||||
Don\[cq]t load spmenu configuration (\[ti]/.spmenu or
|
Don\[cq]t load spmenu configuration (\[ti]/.config/spmenu/spmenu.conf,
|
||||||
\[ti]/.config/spmenu/spmenurc)
|
\[ti]/.spmenurc or \[ti]/.config/spmenu/spmenurc)
|
||||||
.TP
|
.TP
|
||||||
\f[V]-v, --version\f[R]
|
\f[V]-v, --version\f[R]
|
||||||
Print spmenu version to stdout
|
Print spmenu version to stdout
|
||||||
|
|
5
spmenu.c
5
spmenu.c
|
@ -161,6 +161,11 @@ static int imageh = 0;
|
||||||
static int imageg = 0;
|
static int imageg = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if USECONFIG
|
||||||
|
static int cconf = 0; // custom config path
|
||||||
|
static char *argconf = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
// set an integer to 1 if we have rtl enabled, this saves a lot of lines and duplicate code
|
// set an integer to 1 if we have rtl enabled, this saves a lot of lines and duplicate code
|
||||||
#if USERTL
|
#if USERTL
|
||||||
static int isrtl = 1;
|
static int isrtl = 1;
|
||||||
|
|
Loading…
Reference in a new issue