soenkehahn / cradle

Rust library for running child processes
Creative Commons Zero v1.0 Universal
37 stars 5 forks source link

Globs #48

Open casey opened 3 years ago

casey commented 3 years ago

There are some kinds of string expansion that the shell does that it would be nice to support. They're very different features, but they all fall into the category of "modify this string in some useful way", so I thought I'd put them all in the same issue.

They could be supported separately, but it might also be useful to have something that does all the expansions you might want, in a reasonable order, with a single helper. Like Expand("~/$SRC/**/*.rs"). The reasonable order is probably whatever bash does.

Globs

$ cp *.txt foo
cmd!("cp", ExpandGlob("*.txt"), "foo");

It would also be nice to support ** globs:

$ cp src/**/*.rs foo
cmd!("cp", ExpandGlob("src/**/*.rs"), "foo");

Variable interpolation

$ cd $HOME/bin
cmd!("cd", ExpandVar("$HOME/bin"));

Tilde expansion

$ cat ~rodarmor/src/agora/src/main.rs
cmd!("cat", ExpandTilde("~rodarmor/src/agora/src/main.rs"));

Brace expansion

$ mv foo.{txt,bin}
cmd!("mv", ExpandBrace("foo.{txt,bin}"));
soenkehahn commented 3 years ago

I like this idea. I'm a bit worried about having to re-implement bash's expansion behavior.

casey commented 3 years ago

I think there are crates for most of these things:

Brace expansion is the craziest, and there's no crate for that.

One nice thing is that these things could all be tested against bash itself, to make sure that they behave the same.