From 1634321bd2fd31c55f7406accee446255e5b65cd Mon Sep 17 00:00:00 2001 From: mawalu Date: Sat, 16 Oct 2021 12:58:11 +0200 Subject: [PATCH] Search multiple locations for profiles --- configs/config.json | 10 ---------- lib/utils.nim | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 13 deletions(-) delete mode 100644 configs/config.json diff --git a/configs/config.json b/configs/config.json deleted file mode 100644 index 4f0836f..0000000 --- a/configs/config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "mount": [], - "romount": ["/etc", "/var", "/usr", "/opt", ".oh-my-zsh", ".zsh", ".zshrc"], - "symlinks": [ - {"src": "usr/lib", "dst": "/lib"}, - {"src": "usr/lib64", "dst": "/lib64"}, - {"src": "usr/bin", "dst": "/bin"}, - {"src": "usr/sbin", "dst": "/sbin"} - ] -} diff --git a/lib/utils.nim b/lib/utils.nim index 3eaa065..75b70a1 100644 --- a/lib/utils.nim +++ b/lib/utils.nim @@ -15,9 +15,19 @@ proc checkRelativePath*(p: string): string = getHomeDir().joinPath(p) proc getProfilePath*(profile: string): string = - getConfigDir() - .joinPath(APP_NAME) - .joinPath(profile) + let pid = getCurrentProcessId() + + for path in [ + getConfigDir().joinPath(APP_NAME), + &"/usr/share/{APP_NAME}", + parentDir(expandSymlink(&"/proc/{pid}/exe")).joinPath("configs") + ]: + let file = path.joinPath(profile) + + if fileExists(file): + return file + + raise newException(IOError, "Profile not found") proc getProfilePath*(args: Args): string = getProfilePath(args.getProfile())