written by Daniel in homelabpoweruser on Fri Oct 01 2021

Dotfiles

Dotfiles are configuration files, typically for command line programs. They are named after a Unix convention of starting their name with a dot .. Dotfiles hold configuration for programs like bash, zsh, vim and git.

I keep all my dotfiles in a git repository. That way I have all my settings backed up, so that I can quickly transfer them to a new machine. Dotfiles obviously save time when setting up a new laptop or desktop, but they are so easy to use -- just copy them to your home directory -- that I can use them even on one-off virtual machines and servers.

In addition to the actual dotfiles, which hold configuration for the shell and other programs, my dotfiles repository contains a few scripts for setting up a new machine. Some dotfiles hold secrets and are encrypted.

Actual dotfiles

Most of my dotfiles reside in $HOME. Some are in ~/.config ($XDG_CONFIG_HOME), which is IMHO way better, but sadly most programs dump dotfiles in the home directory.

These dotfiles are in the root of the git repo. Installing them is as easy as copying to the home directory. This is what bootstrap.sh does.

My dotfiles mostly define the behavior of bash, which I use as my shell, as well as the shell prompt. Other than the shell, there are files for git, vim and curl.

Screenshot of my shell prompt

New machine setup

The setup directory holds scripts which help setting up a new machine. They are MacOS-specific, except for secrets.sh, though it doesn't make much sense to put secrets like SSH keys and configs with passwords anywhere else than on my main machine.

macos.sh

This script configures a new, clean MacOS installation. It mostly sets options you would configure in the System Preferences GUI (like wallpaper, Dock preferences), but also some more hidden settings like showing path in Finder at all times. There are some downright esoteric settings like disabling (unbearably slow) window animations in Apple Mail.

brew.sh

Updates Homebrew and installs formulae and casks. Also switches the shell to less ancient, brew-installed bash.

vscode.sh

Copies settings and keybindings to VSCode's configuration folder and installs a couple of extensions.

mount.sh

Extends automount config /etc/auto_master with /etc/auto_nfs, which mounts my NAS as a NFS share. Also comes in handy after a system update, because MacOS updates reset the auto_master for some reason.

sudo.sh

Allows using Touch ID for sudo instead of password. Also gets reset by a system update.

Secrets

Last script in the repo is setup/secrets.sh. It takes care of decrypting and installing dotfiles which contain secrets such as private keys and passwords and cannot be commited to a git repo in plaintext. Before running the script, ensure you have gpg available (such as GnuPG on Mac, installed by brew.sh) and a private key that can decrypt your secrets. It's important to back this private key up to a password manager.

I prefer to keep all my dotfiles with secrets in ~/.secrets/, which makes it easy to back them up. I then symlink the files to their original location:

$ ln -s $SECRETS_DIR/.ssh/* ~/.ssh/

That's all there is to my dotfiles so far. Thanks to Mathias Bynens and his awesome dotfiles repo (HN discussion), which were the inspiration and basis for mine.