~sircmpwn/rc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] interp: expand tilde

Curtis Arthaud <uku82@gmx.fr>
Details
Message ID
<20230918124807.9611-1-uku82@gmx.fr>
DKIM signature
missing
Download raw message
Patch: +12 -0
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
Details
Message ID
<CVOTG8QVSH38.2VSSH97KNJGMP@taiga>
In-Reply-To
<20230918124807.9611-1-uku82@gmx.fr> (view parent)
DKIM signature
missing
Download raw message
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
Reply to thread Export thread (mbox)