Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

301–310 of 408 posts

Re: Scripts I wrote that I use all the time

#301

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…

Given the nature of current operating systems and applications, do you think the idea of “one tool doing one job well” has been abandoned? If so, do you think a return to this model would help bring some innovation back to software development? Rob Pike: Those days are dead and gone and the eulogy was delivered by Perl.

Oh I hate that paradigm. Well, maybe chmod and ls rsync and curl all do they OWN thing very well but every time I am using one of those tools I have to remember if i.e. more detailed response is -v or maybe -vvv or --verbose or -x for some reason because maintainer felt like it at 2:32 in the morning 17 years ago... Some consistency would help, but... Probably it is impossible the flame war over -R being recursive or read-only would never end.

Re: Scripts I wrote that I use all the time

#302

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…

The moment of true enlightenment is when you finally decide to once and for all memorize all the arguments and their order for those command line utilities that you use at an interval that's just at the edge of your memory: xargs, find, curl, rsync, etc. That, plus knowing how to parse a man file to actually understand how to use a command (a skill that takes years to master) pretty much removes the need for most ali…

Why would I even attempt to do that? Life is too short to try to remember something like that. Maybe 20 years ago when internet was not that common. Or maybe if you are a hacker, hacking other peoples machines. Me? Just some dev trying yo make some money to feed my family? I prefer to have a walk to the woods.

Re: Scripts I wrote that I use all the time

#303

Earlier quoted context omitted.

I need this *so* often that I programmed my shell to execute 'cd ..' every time I press KP/ i.e. '/' on the keypad, without having to hit Return. Other single-key bindings I use often are: KP* executes 'ls' KP- executes 'cd -' KP+ executes 'make -j `nproc`'

How? Readline macros?

Literally with my own shell: https://github.com/cosmos72/schemesh

Re: Scripts I wrote that I use all the time

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

I see other people mentioning env and mise does this too, with additional support to add on extra env overrides with a dedicated file such as for example .mise.testing.toml config and running something like:

MISE_ENV=testing bun run test

(“testing” in this example can be whatever you like)

Re: Scripts I wrote that I use all the time

#306

> alphabet just prints the English alphabet in upper and lowercase. I use this surprisingly often (probably about once a month) I genuinely wonder, why would anyone want to use this, often?

As a programmer, you sometimes want to make an alphabet lookup table. So, something like:

  var alpha_lu = "abcdefghijklmnopqrstuvwxyz";
Typing it out by hand is error prone as it's not easy to see if you've swapped the order or missed a character.

I've needed the alphabet string or lookup rarely, but I have needed it before. Some applications could include making your own UUID function, making a small random naming scheme, associating small categorical numbers to letters, etc.

The author of article mentioned they do web development, so it's not hard to imagine they've had to create a URL shortener, maybe more than once. So, for example, creating a small name could look like:

  function small_name(len) {
    let a = "abcdefghijklmnopqrstuvwxyz",
        v = [];
    for (let i=0; i
Dealing with strings, dealing with hashes, random names, etc., one could imagine needing to do functions like this, or functions that are adjacent to these types of tasks, at least once a month.

Just a guess on my part though.

Re: Scripts I wrote that I use all the time

#307

Earlier quoted context omitted.

Other examples where native features are better than these self-made scripts... > vim [...] I select a region and then run :' !markdownquote Just select the first column with ctrl-v, then "i> " then escape. That's 4 keys after the selection, instead of 20. > u+ 2025 returns ñ, LATIN SMALL LETTER N WITH TILDE `unicode` is widely available, has a good default search, and many options. BTW, I wonder why "2025" matched "…

> `unicode` is widely available It's not installed by default on macOS or Ubuntu, for me.

You are right but

  $ unicode
  Command 'unicode' not found, but can be installed with:
  sudo apt install unicode
and it did. So it really was available. That's Debian 11.

Re: Scripts I wrote that I use all the time

#308

Regarding the `line` script, just a note that sed can print an arbitrary line from a file, no need to invoke a pipeline of cat, head, and tail: sed -n 2p file prints the second line of file. The advantage sed has over this line script is it can also print more than one line, should you need to: sed -n 2,4p file prints lines 2 through 4, inclusive.

If you'd like to print the middle of a file, try out `body`: https://github.com/megamansec/body

Re: Scripts I wrote that I use all the time

#309

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…

man, i couldn't live without alias ..='cd ..' or alias ...='cd ../..' to this day, i still get tripped up when using a shell for the first time without those as they're muscle memory now.

you can configure Alt+Left to go up level

Re: Scripts I wrote that I use all the time

#310
The Gen AI tooling is exceptionally good at doing these sorts of things, and way more than just "mkdir $1 && cd $1". For example:

I have used it to build an "escmd" tool for interacting with Elasticsearch. It makes the available commands much more discoverable, the output it formats in tables, and gets rid of sending JSON to a curl command.

A variety of small tools that interact with Jira (list my tickets, show tickets that are tagged as needing ops interaction in the current release).

A tool to interact with our docker registry to list available tags and to modify tags, including colorizing them based on the sha hash of the image so it's obvious which ones are the same. We manage docker container deploys based on tags so if we "cptag stg prod" on a project, that releases the staging artifact to production, but we also tag them by build date and git commit hash, so we're often working with 5-7 tags.

Script to send a "Software has successfully been released" message via gmail from the command-line.

A program to "waituntil" a certain time to run a command: "waituntil 20:00 && run_release", with nice display of a countdown.

I have a problem with working on too many things at once and then committing unrelated things tagged with a particular Jira case. So I had it write me a commit program that lists my tickets, shows the changed files, and lets me select which ones go with that ticket.

All these are things I could have built before, but would have taken me hours each. With the GenAI, they take 5-15 minutes of my attention to build something like this. And Gen AI seems really, really great at building these small, independent tools.

Post reply on HN