mirror of
https://github.com/swaywm/sway.git
synced 2026-04-29 06:46:22 -04:00
Introduce shell_expand
This performs shell expansion without field splitting. This fixes issues with filenames containing spaces. This commit also cleans up complicated logic to join fields and to set XDG_CONFIG_HOME.
This commit is contained in:
parent
6acbe84fdd
commit
8389047b47
8 changed files with 121 additions and 114 deletions
|
|
@ -1,10 +1,10 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <wordexp.h>
|
||||
#include "log.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "readline.h"
|
||||
#include "shexp.h"
|
||||
#include "swaynag/swaynag.h"
|
||||
#include "swaynag/types.h"
|
||||
#include "util.h"
|
||||
|
|
@ -306,31 +306,17 @@ char *swaynag_get_config_path(void) {
|
|||
SYSCONFDIR "/swaynag/config",
|
||||
};
|
||||
|
||||
if (!getenv("XDG_CONFIG_HOME")) {
|
||||
char *home = getenv("HOME");
|
||||
char *config_home = malloc(strlen(home) + strlen("/.config") + 1);
|
||||
if (!config_home) {
|
||||
wlr_log(WLR_ERROR, "Unable to allocate $HOME/.config");
|
||||
} else {
|
||||
strcpy(config_home, home);
|
||||
strcat(config_home, "/.config");
|
||||
setenv("XDG_CONFIG_HOME", config_home, 1);
|
||||
wlr_log(WLR_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
|
||||
free(config_home);
|
||||
}
|
||||
char *config_home = getenv("XDG_CONFIG_HOME");
|
||||
if (config_home == NULL || config_home[0] == '\0') {
|
||||
config_paths[1] = "$HOME/.config/swaynag/config";
|
||||
}
|
||||
|
||||
wordexp_t p;
|
||||
char *path;
|
||||
for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) {
|
||||
if (wordexp(config_paths[i], &p, 0) == 0) {
|
||||
path = strdup(p.we_wordv[0]);
|
||||
wordfree(&p);
|
||||
if (file_exists(path)) {
|
||||
return path;
|
||||
}
|
||||
free(path);
|
||||
char *path = strdup(config_paths[i]);
|
||||
if (shell_expand(&path) && file_exists(path)) {
|
||||
return path;
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue