For fast iteration with pipes, using only basic unix tools, and arguably less risky to fat-fingering, I write it in a file, and use watch -n1. Easy to modify, temporarily comment parts of it, etc...
Also, I wrote this plog function (for pipe-log, or something):
plog() {
local msg=${1:-plog}
tee >(sed -e "s/^/[$msg] /" | cat 1>&2 )
}
That allows me to see what's happening in the middle steps of the pipeline.
rgrau, I'm halfway through your field guide. I appreciate how concise the text portions are, and how, although each section teaches one thing at a time, you are sometimes willing to leave the reader with "here are all the major incantations, figure out the details of each one and appreciate them" - such as in section 4.4.
Learned several new bashisms which i will put into my computer tip memorization deck. Thank you for writing.
This is super cool. There's so much good stuff in there I'm gonna have to come back a few times just to digest it all! Also looking forward to some of the links at the bottom.
Do you have a standard template you use for your scripts? You kind of touch on this in section 4.20.1 but don't go too deep.
Also have you done any work with writing zsh (or bash) completions? I feel like having good completions would make my scripts magnitudes more handy, but I've had trouble finding good starter resources.
At the start it provides a stacktrace function which can also be used to notify you if your script has failed (e.g. via xmpp, e-mail, etc.). It is not my own creation, as I found it somewhere a few years ago, but found it super useful over time.
In addition, there are two versions for checking for dependencies. The first lets you communicate instructions for every tool that is required while the second can be used if you simply want to communicate the list of programs that is missing.
The third part is about named parameters, which can be helpful if you don't want to use positional parameters.
Most of my scripts start with that template on 4.20.1. That's the baseline. But soon enough they have 4.22 and 4.25.
I never liked those "bare minimum templates" that are 100 lines, because usually the scripts I write start being just a couple dozen lines. If they grow, I add things on a need basis, but the ratio of logic/template has to be >0 always.
wrt completions, doing smart completions is hard, and the zsh ones are not very intuitive to me. I try to make my scripts work with "compdef _gnu_generic ". It goes a long way, and it's an incentive to write proper --help
Also, I wrote this plog function (for pipe-log, or something):
That allows me to see what's happening in the middle steps of the pipeline.I ended up compiling a list of tricks like that in https://raimonster.com/scripting-field-guide/ , in case anyone is interested (and feedback is appreciated)