Skip to content

Clean $HOME, Clean Mind

I don’t like a messy home. Home is where all your stuff lives and if you want to find something, it’s easier if there’s not a bunch of clutter in the way. This is true in your physical home and your digital $HOME. Most Linux distributions and macOS populate your $HOME with directories you never asked for. The difference is whether you can rid yourself of them. On Linux they come from xdg-user-dirs. You can remove or disable it, delete the directories, and they stay gone. macOS has no such switch: delete its home directories and the system quietly recreates them. So on the Mac you can’t remove them… but you can hide them. ...

Porcelain

A little indicator on my prompt tells me the state of the git repo I’m in, if I’m in one. It’s quite minimal. Green tick: repo is clean; yellow cross: there are changes; red dot: there are merge conflicts. It’s a nice visual cue and for the longest time and the following code in my ~/.zshrc file made it possible. 1 2 3 4 5 6 7 8 9 10 git_status_prompt() { git rev-parse --git-dir >/dev/null 2>&1 || return if git diff --name-only --diff-filter=U 2>/dev/null | grep -q .; then echo " %F{red}●%f" elif git status --porcelain 2>/dev/null | grep -q .; then echo " %F{yellow}✘%f" else echo " %F{green}✓%f" fi } This works fine. It does what it’s supposed to… It’s ugly though. ...

Change Directory, List

When moving around in my terminal, I use two commands in sequence all the time. You’ll know them, they are cd and ls. Change directory, then list the contents of that directory. I decided this was getting annoying. Why is there not a single command to do this? Why not make one? I first thought an alias might work, but then I realised you cannot call an alias, hand it a variable and have it do something after that variable. <alias> <user variable> <second action> is just not possible. ...

Terminal Abbreviations

Typing takes time. Typing without typos is an art. Fixing mistakes in a terminal command is a pain in the neck. Luckily there’s such a thing as aliases. An alias lets you set a keyword and a command it should expand to. For example, I have set a super simple one, which is widely used: alias ..='cd ..'. This allows me to write .. in terminal and it will act like cd .., saving me typing a c, a d and a space. This seems minor, but when you imagine how often I need to go up a directory in terminal, it’s a huge timesaver. ...

The Best Function I Ever Stole

Extracting archives is a pain on Linux. There are just so many types and so many programs to extract each type. A .tar.gz file is extracted using the program GNU tar, but for a .zip file, you’d need unzip. What’s that? You’ve got a .7z file? Yeah-no, can’t use either of the before mentioned extractors, you need 7-zip. Got a .rar, you’d need… well, you get the point. What’s more, some of these programs require flags you’ll need to use to actually extract an archive. For example, to extract a tar file, you might do something like tar xvf <filename>. For a 7z file though, it’d be 7z x <filename>. Other extraction programs don’t require flags at all though, just the name of the extraction program followed by the file to extract. This sounds simple enough, but wait… what was the name of the program to unzip .bz2 files again? ...