feat: support -c option to specified config file
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <ctype.h>
|
||||
#include <libgen.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -2307,7 +2308,14 @@ void parse_config_file(Config *config, const char *file_path) {
|
||||
// Relative path
|
||||
|
||||
const char *mangoconfig = getenv("MANGOCONFIG");
|
||||
if (mangoconfig && mangoconfig[0] != '\0') {
|
||||
|
||||
if (cli_config_path) {
|
||||
char *config_path = strdup(cli_config_path);
|
||||
char *config_dir = dirname(config_path);
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", config_dir,
|
||||
file_path + 1);
|
||||
free(config_path);
|
||||
} else if (mangoconfig && mangoconfig[0] != '\0') {
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", mangoconfig,
|
||||
file_path + 1);
|
||||
} else {
|
||||
@@ -3040,7 +3048,9 @@ void parse_config(void) {
|
||||
const char *mangoconfig = getenv("MANGOCONFIG");
|
||||
|
||||
// 如果 MANGOCONFIG 环境变量不存在或为空,则使用 HOME 环境变量
|
||||
if (!mangoconfig || mangoconfig[0] == '\0') {
|
||||
if (cli_config_path) {
|
||||
snprintf(filename, sizeof(filename), "%s", cli_config_path);
|
||||
} else if (!mangoconfig || mangoconfig[0] == '\0') {
|
||||
// 获取当前用户家目录
|
||||
const char *homedir = getenv("HOME");
|
||||
if (!homedir) {
|
||||
|
||||
@@ -29,7 +29,12 @@ int isdescprocess(pid_t p, pid_t c) {
|
||||
char *get_autostart_path(char *autostart_path, uint32_t buf_size) {
|
||||
const char *mangoconfig = getenv("MANGOCONFIG");
|
||||
|
||||
if (mangoconfig && mangoconfig[0] != '\0') {
|
||||
if (cli_config_path) {
|
||||
char *config_path = strdup(cli_config_path);
|
||||
char *config_dir = dirname(config_path);
|
||||
snprintf(autostart_path, buf_size, "%s/autostart.sh", config_dir);
|
||||
free(config_path);
|
||||
} else if (mangoconfig && mangoconfig[0] != '\0') {
|
||||
snprintf(autostart_path, buf_size, "%s/autostart.sh", mangoconfig);
|
||||
} else {
|
||||
const char *homedir = getenv("HOME");
|
||||
|
||||
@@ -852,6 +852,7 @@ struct dvec2 *baked_points_focus;
|
||||
static struct wl_event_source *hide_source;
|
||||
static bool cursor_hidden = false;
|
||||
static bool tag_combo = false;
|
||||
static const char *cli_config_path = NULL;
|
||||
static KeyMode keymode = {
|
||||
.mode = {'d', 'e', 'f', 'a', 'u', 'l', 't', '\0'},
|
||||
.isdefault = true,
|
||||
@@ -5908,13 +5909,15 @@ int main(int argc, char *argv[]) {
|
||||
char *startup_cmd = NULL;
|
||||
int c;
|
||||
|
||||
while ((c = getopt(argc, argv, "s:hdv")) != -1) {
|
||||
while ((c = getopt(argc, argv, "s:c:hdv")) != -1) {
|
||||
if (c == 's')
|
||||
startup_cmd = optarg;
|
||||
else if (c == 'd')
|
||||
log_level = WLR_DEBUG;
|
||||
else if (c == 'v')
|
||||
die("mango " VERSION);
|
||||
else if (c == 'c')
|
||||
cli_config_path = optarg;
|
||||
else
|
||||
goto usage;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user