Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

291–300 of 408 posts

Re: Scripts I wrote that I use all the time

#291

Earlier quoted context omitted.

15 years of Linux and I learn something new all the time...

Its why I keep coming back, now how do I remember to use this and not go back to using tmpfiles :)

I use Warp terminal for couple of years, and recently they embeeded AI into it. At first I was irritated, disabled it, but AI Agent is built in as an optional mode (Cmd-I to toggle). And I found myself using it more and more often for commands that I have no capacity or will to remember or dig through the man pages (from "figure out my IP address on wifi interface" to "make ffmpeg do this or that"). It's fast and can iterate over own errors, and now I can't resist using it regularly. Removes the need for "tools to memorize commands" entirely.

Re: Scripts I wrote that I use all the time

#292
post #250

I have a bunch, but one that I rarely see mentioned but use all the time is memo(1) ( https://github.com/aktau/dotfiles/blob/master/bin/memo ). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input…

Caching some API call because it is expensive and use cached data many months later because of bash suggestion :(

Re: Scripts I wrote that I use all the time

#295
post #287
post #236

Earlier quoted context omitted.

> reference them when forgetting syntax If you have to do that, the script needs improvement. Always add a `--help` which explains what it does and what arguments it takes.

If you write these sorts of things in Python, argparse is worth investigating: https://docs.python.org/3/library/argparse.html - it's pretty easy to use, makes it easy to separate the command line handling from the rest of the code, and, importantly, will generate a --help page for you. And if you want something it can't do, you can still always write the code yourself!

I don’t like Python in general, but even so I’ll say that argparse is indeed very nice. When I was writing ruby, I always felt that OptionParser¹ wasn’t as good. Swift has Argument Parser², officially from Apple, which is quite featureful. For shell, I have a a couple of bespoke patterns I have been reusing in every script for many years.

¹ https://github.com/ruby/optparse

² https://github.com/apple/swift-argument-parser

Re: Scripts I wrote that I use all the time

#297
17 years ago I wrote a short VBA macro that takes the high life’s range of cells, concatenates the values into a comma separated list, then opens the list in notepad for easy copy and further use. I can’t begin to count the number of executions by myself and those i have shared it with.

Re: Scripts I wrote that I use all the time

#298
post #262

I've written on this before, but I have an extensive collection of "at" scripts. This started 25+ years ago when I dragged a PC tower running BSD to a friend's house, and their network differed from mine. So I wrote an @friend script which did a bunch of ifconfig foo. Over time that's grown to an @foo script for every project I work on, every place I frequent that has some kind of specific setup. They are prefixed wi…

I'm stealing the top comment here because you probably know what I'm asking. I've always wanted a linux directory hook that runs some action. Say I have a scripts dir filled with 10 different shells scripts. I could easily have a readme or something to remember what they all do. What I want is some hook in a dir that every time I cd into that dir it runs the hook. Most of the time it would be a simple 'cat usage.txt'…

As other comments say, direnv does that, but honestly you should look into mise-en-place (mise) which is really great, and also includes a "mini-direnv"

Re: Scripts I wrote that I use all the time

#300
post #250

I have a bunch, but one that I rarely see mentioned but use all the time is memo(1) ( https://github.com/aktau/dotfiles/blob/master/bin/memo ). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input…

Dude, this is _awesome_. Thank you for sharing!
Post reply on HN