Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

121–130 of 408 posts

Re: Scripts I wrote that I use all the time

#121

My fav script to unpack anything, found a few years ago somewhere # ex - archive extractor # usage: ex function ex() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.tar.xz) tar xf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' can…

Very nice and clean

Re: Scripts I wrote that I use all the time

#122

My fav script to unpack anything, found a few years ago somewhere # ex - archive extractor # usage: ex function ex() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.tar.xz) tar xf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' can…

I use dtrx, which also ensures that all files are extracted into a folder.

Re: Scripts I wrote that I use all the time

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

Instead of trash, reimplementing rm (to only really delete after some time or depending on resource usage or to shred of you are paranoid if the goal is to really delete something) or using zfs makes much more sense.

Re: Scripts I wrote that I use all the time

#124

Nice! Tangentially related: I built a (MacOS only) tool called clippy to be a much better pbcopy. It was just added to homebrew core. Among other things, it auto-detects when you want files as references so they paste into GUI apps as uploads, not bytes. clippy image.png # then paste into Slack, etc. as upload clippy -r # copy most recent download pasty # copy file in Finder, then paste actual file here https://githu…

Awesome. Gonna check this out.

Re: Scripts I wrote that I use all the time

#125
I use these two all the time to encode and cut mp4s.

The flags are for maximum compatibility (e.g. without them, some MP4s don't play in WhatsApp, or Discord on mobile, or whatever.)

    ffmp4() {
        input_file="$1"
        output_file="${input_file%.*}_sd.mp4"

        ffmpeg -i "$input_file" -c:v libx264 -crf 33 -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags faststart "$output_file"

        echo "Compressed video saved as: $output_file"
    }
    
    
ffmp4 foo.webm

-> foo_sd.mp4

    fftime() {
        input_file="$1"
        output_file="${input_file%.*}_cut.mp4"
        ffmpeg -i "$input_file" -c copy -ss "$2" -to "$3" "$output_file"

        echo "Cut video saved as: $output_file"
    }

fftime foo.mp4 01:30 01:45

-> foo_cut.mp4

Note, fftime copies the audio and video data without re-encoding, which can be a little janky, but often works fine, and can be much (100x) faster on large files. To re-encode just remove "-c copy"

Re: Scripts I wrote that I use all the time

#126
post #71

Earlier quoted context omitted.

You can apply your dotfiles to servers you SSH into rather easily. I'm not sure what your workflow is like but frameworks like zsh4humans have this built in, and there are tools like sshrc that handle it as well. Just automate the sync on SSH connection. This also applies to containers if you ssh into them.

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.

Re: Scripts I wrote that I use all the time

#127
post #46

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…

I think it's more likely to say that this comes from a place of laziness than some enlightened peak. (I say this as someone who does the same, and is lazy). When I watch the work of coworkers or friends who have gone these rabbit holes of customization I always learn some interesting new tools to use - lately I've added atuin, fzf, and a few others to my linux install

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

Re: Scripts I wrote that I use all the time

#128
post #38

I have mkcd exactly ( I wonder how many of us do, it's so obvious) I have almost the same, but differently named with scratch(day), copy(xc), markdown quote(blockquote), murder, waitfor, tryna, etc. I used to use telegram-send with a custom notification sounnd a lot for notifications from long-running scripts if I walked away from the laptop. I used to have one called timespeak that would speak the time to me every h…

Doesn’t the built in `take` do exactly what `mkcd` does? Or is `take` a zsh/macos specific thing?

Edit: looks like it’s a zsh thing

Re: Scripts I wrote that I use all the time

#129

My fav script to unpack anything, found a few years ago somewhere # ex - archive extractor # usage: ex function ex() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.tar.xz) tar xf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' can…

Now, add inotify and a systemd user service and you would be getting somewhere. Also packaged versions of that exist already.

So, you created a square wheel, instead of a NASA wheel.

Post reply on HN