Byron / open-rs

Open a path or URL with the system-defined program
http://byron.github.io/open-rs
MIT License
319 stars 49 forks source link

open::with args #62

Closed benjajaja closed 1 year ago

benjajaja commented 1 year ago

open::with(path, "firefox --new-window --more-flags") primitively passes the args to Command. Primitively, because String::split_whitespace might not be good enough. There is a crate shell-words that would do the right thing, but I don't want to bring in a dependency unless asked.

Related to #42, but more primitive and only for unix - no idea about win/mac.

benjajaja commented 1 year ago

I forgot to clarify: current behaviour (on unix) of with only works if the argument is a single word. That is: Command::new("firefox --new-window").arg(<path-to-open>).spawn() fails with something like No such file or directory.

Splitting the string is backwards compatible and only enables the option to also use prog --with args.

My use case is actually the opposite of joining strings. By default, I use that. The user may set a setting to open with a specific command though, and then I use with. That setting would just be a string, and not a list of strings with a minimum length of 1.

Byron commented 1 year ago

Thanks for the clarification.

Splitting the string is backwards compatible and only enables the option to also use prog --with args

I think that's not the case if applications are passed by full path, and that contains a space. Even though not common, it's not unusual enough to me to break it with an alternative option available.

My use case is actually the opposite of joining strings. By default, I use that. The user may set a setting to open with a specific command though, and then I use with. That setting would just be a string, and not a list of strings with a minimum length of 1.

It seems like a method that supporting arguments would cover your case better, as args could be empty until the user indicates it otherwise.

benjajaja commented 1 year ago

Ah, spaces in the path, I didn't think of that. I will make a with_args then.

Byron commented 1 year ago

With the latest release and the addition of with_command(), it's possible to add arguments before spawning the launcher, which is more general than the method proposed here.

Here is the new release.