Skip to content

Commit 28c0159

Browse files
committed
Platform: add $EXE_PATH/../share to dataDir
Support loading presets when fastfetch is installed in a special path. eg. `/opt/homebrew/bin/`
1 parent ce47a82 commit 28c0159

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/detection/terminalshell/terminalshell_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void getProcessInformation(pid_t pid, FFstrbuf* processName, FFstrbuf* ex
4848
if(length > 0)
4949
exe->length = (uint32_t)length;
5050

51-
#else
51+
#elif defined(__FreeBSD__)
5252

5353
size_t size = exe->allocated;
5454
if(!sysctl(

src/util/platform/FFPlatform_unix.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@
55

66
#include <unistd.h>
77
#include <pwd.h>
8+
#include <limits.h>
89
#include <sys/utsname.h>
910

11+
#ifdef __APPLE__
12+
#include <libproc.h>
13+
#elif defined(__FreeBSD__)
14+
#include <sys/sysctl.h>
15+
#endif
16+
1017
static void platformPathAddEnv(FFlist* dirs, const char* env)
1118
{
1219
const char* envValue = getenv(env);
@@ -82,7 +89,31 @@ static void getDataDirs(FFPlatform* platform)
8289
platformPathAddEnv(&platform->dataDirs, "XDG_DATA_HOME");
8390
ffPlatformPathAddHome(&platform->dataDirs, platform, ".local/share/");
8491

85-
#if defined(__APPLE__)
92+
// Add ${currentExePath}/../share
93+
FF_STRBUF_AUTO_DESTROY exePath = ffStrbufCreateA(PATH_MAX);
94+
#ifdef __linux__
95+
ssize_t exePathLen = readlink("/proc/self/exe", exePath.chars, exePath.allocated);
96+
#elif defined(__APPLE__)
97+
int exePathLen = proc_pidpath((int) getpid(), exePath.chars, exePath.allocated);
98+
#elif defined(__FreeBSD__)
99+
size_t exePathLen = exePath.allocated;
100+
if(sysctl(
101+
(int[]){CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, (int) getpid()}, 4,
102+
exePath.chars, &exePathLen,
103+
NULL, 0
104+
))
105+
exePathLen = 0;
106+
#endif
107+
if (exePathLen > 0)
108+
{
109+
exePath.length = (uint32_t) exePathLen;
110+
ffStrbufSubstrBeforeLastC(&exePath, '/');
111+
ffStrbufSubstrBeforeLastC(&exePath, '/');
112+
ffStrbufAppendS(&exePath, "/share");
113+
ffPlatformPathAddAbsolute(&platform->dataDirs, exePath.chars);
114+
}
115+
116+
#ifdef __APPLE__
86117
ffPlatformPathAddHome(&platform->dataDirs, platform, "Library/Application Support/");
87118
#endif
88119

0 commit comments

Comments
 (0)