Closed chrisdone closed 9 years ago
Interesting! Shelley already has code for searching the PATH. Why does it need to be flagged? Shouldn't it just take time to compile when the user uses it?
Interesting! Shelley already has code for searching the PATH
Sweet. I just cobbled mine together, I expect you'll have something more honed and battle-tested. Can you point me to that code?
Why does it need to be flagged? Shouldn't it just take time to compile when the user uses it?
Oh, was just a thought. It's indeed just compile-time, just adds a bit of time in compilation. If you're cool with that by default, so am I.
Hold that. I'm cloning, I'll have a look around and make a PR for this.
But I don't get the by default bit: doesn't a user choose whether to use this?
But I don't get the by default bit: doesn't a user choose whether to use this?
I just meant that it should build this large module. Nevermind, I was making a big deal out of the build time, it's not that bad.
Anyway, I suppose someone would write:
import Shelly.Bin
And that module brings a bunch of git = cmd "git"
, etc. top-level bindings. What do you think?
https://github.com/yesodweb/Shelly.hs/blob/master/src/Shelly.hs#L573
Right, so can I move the code at here to the top-level as an IO function that can be used from within TH?
sounds good! If it just works on unix for now that is ok (there is the .exe bit at least)
Cool. Alright, I'll make a PR later this evening!
Looking at this more I feel that there are some downsides to the approach as is
1) additional build time and binary size 2) scope pollution, which requires a remap for things I don't even care about and makes the script non-portable 3) the PATH can change from build time to run time
It seems like the issues can be solved by stating which binaries you desire: a white-list api:
generateCmds ["git", "less"]
For point 3, the script no longer has to check for the existence of a binary, although it could warn about the binary not existing.
I can see how you wouldn't want to take this approach in a shell like Hell though.
I've been experimenting with this approach, using template-haskell.
It allows you to just write
git ["status"]
ordate []
orrm ["file"]
. For me this changes scripts from "this is a bit tedious" to "this feels more bash-convenient".Would you be interested in adding such a thing to shelly? It takes some seconds to compile the module (maybe 10) that uses
generateBinaries
, and makes a rather large haddock output, so you might want to make it a flag or something.