shellmet
shellmet copied to clipboard
[RFC] Implement a way to construct pipes
When I need to call pipes I often end with the code like this:
callCommand $ "git diff " <> commit <> " --color=always | diff-highlight | less -rFX"
I can use $| operator but it's not efficient. So maybe having some additional function would be useful and I can rewrite it like this:
pipes $ "git" [commit, "--color=always"] <> "diff-highlight" [] <> "less" ["-rfX"]
Is it possible to call subprocesses directly, without executing the shell sh -c ? Thanks!
@v217 Could you elaborate more on your question? I'm not sure I understand it completely...
@chshersh Sure, if I now write
"sleep" ["1000"]
ghci calls sh -c 'sleep 1000' instead of execve sleep 1000 without calling the shell.
So in your terminal running ps -e you see:
ghci
sh
sleep
@v217 Thanks for the clarification! I see what do you mean now. This happens because we're using callCommand function from the process library here:
- https://github.com/kowainik/shellmet/blob/d701862693c52a9aa1e3a0d563780d00dbebb052/src/Shellmet.hs#L39-L41
This command constructs a process using ShellComand constructor of the CmdSpec data type:
- https://hackage.haskell.org/package/process-1.6.6.0/docs/System-Process.html#t:CmdSpec
According to the documentation (if my understanding is correct), it should be possible to replace callCommand with callProcess to create subprocesses directly. However, I'm afraid to perform this change because I'm not sure how it will behave on various systems (Linux, Windows, macOS). We're currently using shellmet in multiple projects, and they were tested on Windows by volunteers, and we know that the tools work. But I don't have time and capability to test these changes on Windows my myself (and not even sure how to do this), so I'm a bit reluctant to perform this refactoring that can potentially break some production code.
Are there any drawbacks regarding using a command from shell?
@chshersh No, apart from shell scripts not being portable, and any shell bug, security flaw might also affect the haskell script. Anyway Thanks for the callProcess link! I am on ubuntu and I will modify your script to use callProcess. I think, if you want to implement Pipes, you have to use callProcess? Currently I am interested in simple scripting solutions for haskell. I am also experimenting with Shh, the most lightweight scripting solution for haskell, I tried so far.
Ah, I've also been looking at shh and I like the library. Looks like it handles pipes quite nice. Unfortunately, shh works only on Unix system, and for our purposes, we want to be able to run shell commands on Windows as well. That's why shellmet is a simple solution that works for simple cases.
I agree, leaving it that simple is certainly an advantage!
Ah, I've also been looking at
shhand I like the library. Looks like it handles pipes quite nice. Unfortunately,shhworks only on Unix system
Maybe use https://github.com/gregwebs/Shelly.hs which is (ideally) system-agnostic?