sharkdp / shell-functools

Functional programming tools for the shell
MIT License
1.2k stars 49 forks source link

Allow run to accept a string with embedded options/parameters, add quiet run #36

Closed parker-ldc closed 5 years ago

parker-ldc commented 5 years ago

This PR updates the run function to split the command on whitespace before running subprocess.call, so it can have have options/parameters specified, e.g.:

ls | map run 'du -hsc'

it also adds a variant of the run function, runq, which doesn't print anything about what it's doing (because I'm too lazy to parse it out of the command output)

sharkdp commented 5 years ago

Hi, thank you very much for your contribution.

In general, I agree that we should support something like this.

Splitting the argument on spaces can be dangerous. Imagine something like map run 'cmd -s "hello world" where the command would be split into

cmd
-s
"hello
world"

Better strategies might be:

Instead of adding an additional runq command, I would rather like to use something like map run -q or map -q run. The -q/--quiet option could be useful for other commands as well.

What do you think?

parker-ldc commented 5 years ago

You're right about the whitespace issue. Also, my patch was a quicky fix to handle something I was working on and wasn't particularly well thought out.

I've subsequently had a bit of time to delve into the problems I've seen and think I can come up some tests/test cases to demonstrate the issue (and maybe to see if it's just me/my environment), as well as a fix for them.

Sorry to take up your time like this, but I do appreciate the welcoming attitude.