diff --git a/src/common/io/io.h b/src/common/io/io.h index cfe730550..8cca6e147 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -82,6 +82,7 @@ typedef enum FFPathType #define FF_PATHTYPE_ANY (FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY) bool ffPathExists(const char* path, FFPathType pathType); +bool ffPathExpandEnv(const char* in, FFstrbuf* out); FF_C_SCANF(2, 3) const char* ffGetTerminalResponse(const char* request, const char* format, ...); diff --git a/src/common/io/io_unix.c b/src/common/io/io_unix.c index 7680cab81..f0a69c537 100644 --- a/src/common/io/io_unix.c +++ b/src/common/io/io_unix.c @@ -107,6 +107,11 @@ bool ffPathExists(const char* path, FFPathType type) return false; } +bool ffPathExpandEnv(const char* in, FFstrbuf* out) +{ + return false; +} + const char* ffGetTerminalResponse(const char* request, const char* format, ...) { struct termios oldTerm, newTerm; diff --git a/src/common/io/io_windows.c b/src/common/io/io_windows.c index bf19540a2..2cd916bd8 100644 --- a/src/common/io/io_windows.c +++ b/src/common/io/io_windows.c @@ -98,6 +98,18 @@ bool ffPathExists(const char* path, FFPathType type) return false; } +bool ffPathExpandEnv(const char* in, FFstrbuf* out) +{ + DWORD length = ExpandEnvironmentStringsA(in, NULL, 0); + if (length <= 1) return false; + + ffStrbufClear(out); + ffStrbufEnsureFree(out, (uint32_t)length); + ExpandEnvironmentStringsA(in, out->chars, length); + out->length = (uint32_t)length - 1; + return true; +} + bool ffSuppressIO(bool suppress) { (void) suppress; //Not implemented. diff --git a/src/fastfetch.c b/src/fastfetch.c index 8156b7244..e0e32f9d7 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -693,9 +693,16 @@ static void optionParseConfigFile(FFdata* data, const char* key, const char* val if(isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, value)) return; - //Try to load as a relative path - FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(128); + if (ffPathExpandEnv(value, &absolutePath)) + { + bool success = isJsonConfig ? parseJsoncFile(value) : parseConfigFile(data, absolutePath.chars); + + if(success) + return; + } + + //Try to load as a relative path FF_LIST_FOR_EACH(FFstrbuf, path, instance.state.platform.dataDirs) { diff --git a/src/logo/logo.c b/src/logo/logo.c index 6cb49d1e9..f74818569 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -332,6 +332,11 @@ static void updateLogoPath(void) return; FF_STRBUF_AUTO_DESTROY fullPath = ffStrbufCreate(); + if (ffPathExpandEnv(options->source.chars, &fullPath) && ffPathExists(fullPath.chars, FF_PATHTYPE_FILE)) + { + ffStrbufSet(&options->source, &fullPath); + return; + } FF_LIST_FOR_EACH(FFstrbuf, dataDir, instance.state.platform.dataDirs) {