Shell Tricks That Make Life Easier (and Save Your Sanity)
281–287 of 287 posts
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#282> We’ve all been there. Close tab. I ought to migrate away from shell scripting and just keep the shell for interactive use. Unfortunately I have cursed myself by getting competent-ish with P. shell and Bash scripting. Meaning I end up creating maintenance headaches for my future self. ( Echoes of future self: ... so I asked an LLM to migrate my shell scripts to Rust and ) Anyway with the interactive shell stuff. Yea…
I've been investigating alternative options with bring-your-own-tool for this situation at $JOB, mostly making use of shebangs to trigger environment setup from self-contained utilities packaged with the scripts, and there are some promising options. Things like `uv` to setup a self-contained one-off python venv automatically so you can write in Python instead, possibly with one of the packages that helps with the many subcommands footguns, or to write `xonsh` if you want something more shell script leaning but with Python power. Or you can alternatively go with a language agnostic solution and use shebang triggered `nix-portable` to construct a whole isolated custom environment automatically from a flake.nix and run whatever tools and mishmash of languages you want.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#283The annoying part is not learning these, it’s remembering them at the right time. I’ve started keeping a tiny cheatsheet just to avoid rediscovering the same tricks over and over.
The hard part is when you've reached the point where all your common use cases are covered and you're left with only uncommon cases. Then it's extra hard to remember you had a trick for dealing with the uncommon case.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#284Earlier quoted context omitted.
> This weird command is presented with such a benevolent innocence as if it's the simplest thing in the world. I think it's a question of context and familiarity. To a vim user, like me and, I assume, ahmedfromtunis, their examples do indeed seem simple and natural. Presumably, to an emacs user, the example you quote (if it's quoted literally—I don't use emacs and can't even tell) is just as natural, and assuming som…
> assuming some comfort with emacs is presumably OK in a manual for the software! How do you get familiar with the software, if the manual expects you to be an expert in it already?
It's surely to the detriment of the manual if the first sentence on the first page assumes you already know the software, but, if nowhere in the manual can it address expert users, then the manual isn't going to be very useful for expert users—and it should be!
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#285Its almost ironical that we still use the Terminal - and many use it like in the eighties using Bash - and seem to have forgotten that we should invent a better terminal & shell than doing all the workarounds to handle the quirks of the current systems.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#286> We’ve all been there. Close tab. I ought to migrate away from shell scripting and just keep the shell for interactive use. Unfortunately I have cursed myself by getting competent-ish with P. shell and Bash scripting. Meaning I end up creating maintenance headaches for my future self. ( Echoes of future self: ... so I asked an LLM to migrate my shell scripts to Rust and ) Anyway with the interactive shell stuff. Yea…
I struggle with this all the time. It's easy to start with some shell commands, and nothing beats the direct terminal running nature of a shell script. But at some point you get to where you need to do things shell isn't good at, and the cost of maintaining that part can put weight the ease of direct terminal access. Especially if you then throw in the need to make your solution runnable on a lot of systems, you now…
For some reason shell and Bash is very alluring to me, but Python isn’t. I guess it’s the combination of both having to orchestrate subprocesses and having to deal with all the typical dynamic language bugs that I introduce in the process of writing in a language I usually do not use.
So then I use some static language. Which has even more of an activation cost.
I should just try a better shell than the vaguely Posix compliant ones.
Re: Shell Tricks That Make Life Easier (and Save Your Sanity)
#287I love this, from a comment on the article: He had in his path a script called `\#` that he used to comment out pipe elements like `mycmd1 | \# mycmd2 | mycmd3`. This was how the script was written: ``` #!/bin/sh cat ```