From cbb9576778d86e47158b8e8c09f359943e91aec5 Mon Sep 17 00:00:00 2001 From: Maxwell Jeffress Date: Thu, 16 Jan 2025 07:00:43 +1100 Subject: [PATCH] Add ~ home dir shortcut --- src/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index df45e8a..a5e0130 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include using namespace std; @@ -47,6 +49,12 @@ string findExecutable(string executable) { return output; } +string getHomeDir() { + struct passwd* pw = getpwuid(getuid()); + if (pw && pw->pw_dir) return string(pw->pw_dir); + return ""; +} + vector tokenise(string input) { vector output; string currentArg; @@ -54,6 +62,8 @@ vector tokenise(string input) { if (input[i] == ' ' && !currentArg.empty()) { output.push_back(currentArg); currentArg.clear(); + } else if (input[i] == '~') { + currentArg += getHomeDir(); } else { currentArg += input[i]; }