Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
---
interp/value.ha | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/interp/value.ha b/interp/value.ha
index 2d762b0..4993987 100644
--- a/interp/value.ha
+++ b/interp/value.ha
@@ -5,6 +5,7 @@ use glob;
use io;
use os::exec;
use os;
+use path;
use rt;
use strconv;
use strings;
@@ -20,6 +21,9 @@ export fn expand(state: *state, val: *ast::value, glob: bool) (value | error) =
case let val: ast::string =>
return strings::dup(val);
case let val: ast::argument =>
+ if (strings::hasprefix(val, '~')) {
+ val = expand_tilde(val);
+ };
if (glob && strings::contains(val, '*')) {
return expand_glob(val)?;
};
@@ -92,6 +96,14 @@ export fn expand(state: *state, val: *ast::value, glob: bool) (value | error) =
};
};
+fn expand_tilde(pattern: str) str = {
+ const home = os::getenv("HOME") as str;
+ let buf = path::init(pattern)!;
+ path::popprefix(&buf, "~")!;
+ path::prepend(&buf, home)!;
+ return strings::dup(path::string(&buf));
+};
+
fn expand_glob(pattern: str) (value | error) = {
let result: []value = [];
--
2.42.0
FWIW this omits the ~username form (which expands to /home/username, or
whatever via /etc/passwd maybe?), but I'm cool with this as-is. Thanks!
To git@git.sr.ht:~sircmpwn/rc
b01c720..95387be master -> master