Live data from Hacker News

Scripts I wrote that I use all the time

evanhahn.com

351–360 of 408 posts

Re: Scripts I wrote that I use all the time

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

Loved it too. Made me want to write a schema for other developers to add (tool, frequency_of_use, category, description) tuples.

Re: Scripts I wrote that I use all the time

#352
post #53

I keep meaning to generalize this (directory target, multiple sources, flags), but I get quite a bit of mileage out of this `unmv` script even as it is: #!/bin/sh if test "$#" != 2 then echo 'Error: unmv must have exactly 2 arguments' exit 1 fi exec mv "$2" "$1"

Nice. This can be generalized to a ”mirror” command to swap the arguments of anything.

Re: Scripts I wrote that I use all the time

#354

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…

Think this is the source https://justin.abrah.ms/bash/forgotten_friend_3.html

Re: Scripts I wrote that I use all the time

#355
post #55

I have a bunch of little scripts and aliases I've written over the years, but none are used more than these... alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias .......='cd ../../../../../..'

alias cdtop=’cd $(git rev-parse --show-toplevel)’

Re: Scripts I wrote that I use all the time

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

On Linux you also have

    % cat /proc/sys/kernel/random/uuid
    464a4e91-5ce4-47b6-bb09-8a60fde572fb

Re: Scripts I wrote that I use all the time

#357
post #210

One script I use quite often: function unix() { if [ $# -gt 0 ]; then echo "Arg: $(date -r "$1")" fi echo "Now: $(date) - $(date +%s)" } Prints the current date as UNIX timestamp. If you provide a UNIX timestamp as arg, it prints the arg as human readable date.

Similarly I have for Linux

    epoch () {
        if [[ -z "${1:-}" ]]
        then
                date +'%s'
        else
                date --date="@${1}"
        fi
    }

    % epoch
    1761245789

    % epoch 1761245789
    Thu Oct 23 11:56:29 PDT 2025

Re: Scripts I wrote that I use all the time

#358
post #140
post #55

I have a bunch of little scripts and aliases I've written over the years, but none are used more than these... alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias .......='cd ../../../../../..'

fish lets you cd to a folder without 'cd' although you still need the slashes. I use it all the time. c $> pwd /a/b/c c $> dir1 dir1 $> .. c $> ../.. / $>

zsh also does, with `setopt autocd` https://zsh.sourceforge.io/Intro/intro_16.html

Re: Scripts I wrote that I use all the time

#359

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

In C I've personally always just done 'a' + x, no table needed

Re: Scripts I wrote that I use all the time

#360

Earlier quoted context omitted.

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

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

No one tell him about `set editing-mode vi` or `info readline`
Post reply on HN