Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

281–290 of 408 posts

Re: Scripts I wrote that I use all the time

#281
post #6

This is exactly the kind of stuff I'm most interested in finding on HN. How do other developers work, and how can I get better at my work from it? What's always interesting to me is how many of these I'll see and initially think, "I don't really need that." Because I'm well aware of the effect (which I'm sure has a name - I suppose it's similar to induced demand) of "make $uncommon_task much cheaper" -> "$uncommon_ta…

https://raw.githubusercontent.com/fliptheweb/bash-shortcuts-... has served me very well.

Wow thanks, I'm tattooing this on my right hand now. :)

Re: Scripts I wrote that I use all the time

#282

It's weird how the circle of life progresses for a developer or whatever. - When I was a fresh engineer I used a pretty vanilla shell environment - When I got a year or two of experience, I wrote tons of scripts and bash aliases and had a 1k+ line .bashrc the same as OP - Now, as a more tenured engineer (15 years of experience), I basically just want a vanilla shell with zero distractions, aliases or scripts and use…

For the Infra Engineers out there who still manage fleets of pets, this is double true. You may not have access or be able to use all your shortcut scripts so you better know the raw commands on that unsupported RHEL6 host.

Re: Scripts I wrote that I use all the time

#283

Earlier quoted context omitted.

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'…

direnv does exactly what you describe (and a lot more) using flake.nix. cd into the directory and it automatically runs. I use it in every single project/repository to set environment variables and install project-specific dependencies locked to specific versions.

> direnv does exactly what you describe (and a lot more) using flake.nix

Direnv is awesome! Note, thought, that it does not depend on Nix, just a Unix-like OS and a supported shell: https://direnv.net/#prerequisites

Re: Scripts I wrote that I use all the time

#284

Earlier quoted context omitted.

I'm guessing you haven't worked in Someone Else's environment? The amount of shit you'll get for "applying your dotfiles" on a client machine or a production server is going to be legendary. Same with containers, please don't install random dotfiles inside them. The whole point of a container is to be predictable.

Someone else's environment? That should never happen. You should get your own user account and that's it.

Sometimes we need to use service accounts, so while you do have your own account all the interesting things happen in svc_foo which you cannot add your .files.

Re: Scripts I wrote that I use all the time

#285

Earlier quoted context omitted.

What does your wife, dog, children, chores, and shopping have to do with custom configuration and scripts? Just set up a Git repo online, put your files there, and take a couple of minutes to improve it incrementally when you encounter inconveniences. And just like that, you made your life easier for a marginal effort.

They compete for time.

Don't even try to explain the scripts to wife*, try the dog. At least he'll understand it just as much and be enthusiastic to hear it!

*may not be applicable to all wives, ymmv.

Re: Scripts I wrote that I use all the time

#286
post #266
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…

Slightly related but mise, a tool you can use instead of eg make, has “on enter directory” hooks that can reconfigure your system quite a bit whenever you enter the project directory in the terminal. Initially I was horrified by this idea but I have to admit it’s been quite nice to enter into a directory and everything is set up just right, also for new people joining. It has built in version management of just about…

This is very useful to me and I had no idea, thanks for pointing that feature out!

Re: Scripts I wrote that I use all the time

#287
post #236

Earlier quoted context omitted.

I'd love to see a cost benefit analysis of the author's approach vs yours, which includes the time it took the author to create the scripts, remember/learn to use them/reference them when forgetting syntax, plus time spent migrating whenever changing systems.

> 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!

Re: Scripts I wrote that I use all the time

#288
post #6

This is exactly the kind of stuff I'm most interested in finding on HN. How do other developers work, and how can I get better at my work from it? What's always interesting to me is how many of these I'll see and initially think, "I don't really need that." Because I'm well aware of the effect (which I'm sure has a name - I suppose it's similar to induced demand) of "make $uncommon_task much cheaper" -> "$uncommon_ta…

This is one of the things I miss the most about hacker conferences. The sharing of tools, scripts, tips and tricks. It was, and still is, just as fun as trading cards.

Re: Scripts I wrote that I use all the time

#289

Earlier quoted context omitted.

What does your wife, dog, children, chores, and shopping have to do with custom configuration and scripts? Just set up a Git repo online, put your files there, and take a couple of minutes to improve it incrementally when you encounter inconveniences. And just like that, you made your life easier for a marginal effort.

They compete for time.

I'm saying that makes no sense, as I've wrote in the comment you're replying to.

Re: Scripts I wrote that I use all the time

#290
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…

Another thing I built into memo(1) which I forgot to mention: automatic compression. memo(1) will use available (de)compressors (in order of preference: zstd, lz4, xz, gzip) to (de)compress stored contents. It's surprising how much disk space and IOPS can be saved this way due to redundancy.

I currently only have two memoized commands:

  $ for f in /tmp/memo/aktau/* ; do 
      ls -lh "$f" =(zstd -d 
That's roughly 10x compression ratio.
Post reply on HN