Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

331–340 of 408 posts

Re: Scripts I wrote that I use all the time

#331

While you're creating and testing aliases, it's handy to source your ~/.zshrc whenever you edit it: alias vz="vim ~/.zshrc && . ~/.zshrc" I alias mdfind to grep my .docx files on my Mac: docgrep() { mdfind "\"$@\"" -onlyin /Users/xxxx/Notes 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2) | grep -v -e '/Inactive/' | sort } I use an `anon` function to anonymize my Mac clipboard when I want to paste something to t…

What's the difference between 'source' and '.' ?

nothing afaict

Re: Scripts I wrote that I use all the time

#332

Earlier quoted context omitted.

Atuin is new to me! https://github.com/atuinsh/atuin Discussed 4 months ago: Atuin – Magical Shell History https://news.ycombinator.com/item?id=44364186 - June 2025, 71 comments

I gave it a try a few months ago, but did not work for me. My main issue is that atuin broke my workflow with fzf (If I remember correctly, pressing ctrl + r to lookup my shell history did not work well after installing atuin).

This is configurable! I use atuin, but fzf with ctrl-r.

Re: Scripts I wrote that I use all the time

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

> `curl ... | jq . | awk '...'`

Uhm, jq _is_ as powerful (more) as awk. You can use jq directly and skip awk.

(I know, old habits die hard, and learning functional programming languages is not easy.)

Re: Scripts I wrote that I use all the time

#335

Earlier quoted context omitted.

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.

I thought my wife latex, she loves me for it :D

Re: Scripts I wrote that I use all the time

#336

While you're creating and testing aliases, it's handy to source your ~/.zshrc whenever you edit it: alias vz="vim ~/.zshrc && . ~/.zshrc" I alias mdfind to grep my .docx files on my Mac: docgrep() { mdfind "\"$@\"" -onlyin /Users/xxxx/Notes 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2) | grep -v -e '/Inactive/' | sort } I use an `anon` function to anonymize my Mac clipboard when I want to paste something to t…

What's the difference between 'source' and '.' ?

I think they're the same except '.' is POSIX and 'source' is specific to bash and compatible shells. I personally just use source since it's easier to read and zsh and bash account for basically 100% of my shell usage.

Re: Scripts I wrote that I use all the time

#337
post #33

> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux. The way you’re doing it trashes files sequentially, meaning you hear the trashing sound once per file and ⌘Z in the Finder will only restore the last one. You can improve that (I did it for years) but consider just using the `trash` commands which ships with macOS. Doesn’t use the Finder, so no sound and no ⌘Z, but it’s fast, offici…

> Why prioritise node instead of jq? The latter is considerably less code and even comes preinstalled with macOS, now.

That was my thought. I use jq to pretty print json.

What I have found useful is j2p and p2j to convert to/from python dict format to json format (and pretty print the output). I also have j2p_clip and p2j_clip, which read from and then write to the system clipboard so I don't have to manually pipe in and out.

> Any reason to not simply use `uuidgen`, which ships with macOS and likely your Linux distro?

I also made a uuid, which just runs uuidgen, but then trims the \n. (And maybe copied to clipboard? It was at my old job, and I don't seem to have saved it to my personal computer.)

Re: Scripts I wrote that I use all the time

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

i see no way to name the memo in your examples, so how do you refer to them later?

also, this seems a lot like an automated way to write shell scripts that you can pipe to and from. so why not use a shell script that won't surprise anyone instead of this, which might?

Re: Scripts I wrote that I use all the time

#339
I have a script called catfiles that I store in ~/.local/bin that recursively dumps every source file with an associated file header so I can paste the resulting blob in to Gemini and ChatGPT in order to have a conversation about the changes I would like to make before I send off the resulting prompt to Gemini Code Assist.

Heres my script if anyone is interested in as I find it to be incredibly useful.

find . -type f \( -name ".tf" -o -name ".tfvars" -o -name ".json" -o -name ".hcl" -o -name ".sh" -o -name ".tpl" -o -name ".yml" -o -name ".yaml" -o -name ".py" -o -name ".md" \) -exec sh -c 'for f; do echo "### FILE: $f ###"; cat "$f"; echo; done' sh {} +

Re: Scripts I wrote that I use all the time

#340
post #33

> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux. The way you’re doing it trashes files sequentially, meaning you hear the trashing sound once per file and ⌘Z in the Finder will only restore the last one. You can improve that (I did it for years) but consider just using the `trash` commands which ships with macOS. Doesn’t use the Finder, so no sound and no ⌘Z, but it’s fast, offici…

For trash on macOS, I recommend https://github.com/ali-rantakari/trash Does all the right things and works great. There’s a similar tool that works well on Linux/BSDs that I’ve used for years, but I don’t have my FreeBSD desktop handy to check.

The trash command for macOS that's being talked about above is native in the OS now, since v14 according to its manpage, though I see it may have really been v15[1]

1: https://mjtsai.com/blog/2025/08/26/the-trash-command/

Post reply on HN