2 ms·
For 1-liners there are only 2 real non-shell contenders - Perl and Ruby. Yes you can do them with Python but it ain't pretty.
by cutler 3y ago
For 1-liners there are only 2 real non-shell contenders - Perl and Ruby. Yes you can do them with Python but it ain't pretty.
- rollcat 3y agoOne-liners are meant to be thrown away, so it does not matter if it's pretty or not. If you care enough to keep it, you should consider rewriting it for clarity. That last step does not require using any particular language; e.g. my PS1 started off as an increasingly convoluted one-liner, until I rewrote it in Go.
- cutler 3y agoPS1 in Go? Overkill, doesn't come close.
- rollcat 3y agoDepends on what you're trying to do. If you're shelling out to git(1) or docker(1), rather than e.g. recursively checking for the presence of .git in parent directories, or inspecting ~/.docker/config.json, then the fork+exec overhead is already quite significant. Next if you're parsing ~/.docker/config.json in shell, you're most likely either asking for trouble or (again) shelling out to jq. Writing it all in an interpreted language means you're paying the cost of interpreter startup, which on underpowered systems can take hundreds of milliseconds even when idle. OTOH loading a static binary to memory happens only once, and with Go you can trivially cross-compile. I also have a fallback shell one-liner, without any of the fanciness like displaying the current git branch: https://github.com/rollcat/etc/tree/master/cmd/prompter#i-like-the-prompt-but-your-code-sucks https://github.com/rollcat/etc/tree/master/cmd/prompter#i-li...