What the F are dotfiles and why should I care?

I’m sure we’ve all shared this sort of experience: You grab your recently delivered brand new shiny computer. You’re excited! It’s time to get that baby running, so you plug in the charger and quickly boot it up. Oh snap. It’s faaaaast! Nice!

After sprinting through the system configuration and creating a user account, you log in and figure “ok I’ll just setup a minimum of apps so I can try out some stuff”. So you download Google Chrome. You login to your chrome profile. Then you decide you want to code a bit, see what its like on this keyboard and monitor, so you download VSCode. Thankfully, you can login here and have your profiles and everything transfered. Phew!

However, quickly you realize you need Figma, Postman, iTerm2 (or Warp or whatever you use), some way to visualize your database, your favorite note-taking app and much much more… The pile keeps growing.

The excitement fades a way, and configuring the machine feels like a bit of a drag, so you push it off, move back to your old computer while haphazardly letting the new one do a few installs in the background that you’re half paying attention to.

Feels familiar?

When I got my current M1 Mac, back in early 2021 this was the exact pain I went through, and what should have been a fun afternoon project, just didn’t seem all that fun.

So I thought “there must be a better way to do this”, which after a little bit of googling helped me realize, there is!

Introducing dotfiles!

Dotfiles, at its core is simply just a collection of configuration files and have their name from UNIX based configuration files, which conventionally are named, starting with a dot. Such as for example .bashrc, which is the configuration file for the Bash shell.

Quick disclaimer: If you’re on Windows, I’m afraid I’m not aware if any such solution exists for you, as all my experience with dotfiles is specifically UNIX (MacOs and Linux) based.

Dotfiles are interesting because they fundamentally allow you to backup, move and most importantly; re-use your system configuration files. So on that fateful night back in early 2021, I went to work. Instead of doing what I always do, as described above, I decided to take a different approach. I realized, it was time for my very own set of dotfiles.

So what can dotfiles even do?

As a Macbook user myself, the sweet thing about dotfiles is the repository can end up doing anything.

Earlier I explained that dotfiles are a set of configuration files. And they are! But a common practice is to include a set of non-configuration script files with your repository, because this is really where the magic can happen once you want to configure a new device.

These scripts can:

  • Configure hot corners on Mac
  • Define computer settings (mouse speed, background image, dock layout, toolbar layout and much more)
  • Install app store apps
  • Install non-app store apps, typically done through something like homebrew
  • Install fonts
  • Much much more.

As you can no doubt tell, dotfiles and the accompanying scripts are a very powerful concept.

Here’s a list of what my dotfiles currently help me do:

  • Install XCode Command Line Tools
  • Install Brew
  • Install git
  • Install and update zsh
  • Install Ruby
  • Set ZSH as default shell
  • Copies this entire repo via SSH
  • Copies dotfiles (from ./homedir) to $HOME
  • Installs VIM
  • Installs fonts
  • Installs NVM at set default to latest stable version
  • Sets global npm configuration npm config set save-exact true
  • Sets sensible system defaults according to my preference 🙂

Unfortunately my repository is private – and I recommend you keep yours so too – so I can’t share for inspiration. However, I do want to share what it currently looks like:

How to get started with dotfiles

I once heard somebody say that a dotfiles repository will be the repository you are active on for the longest. I’ve found this to be increasingly true. It’s not something you use every day, but every time I change an important configuration, I want to update my dotfiles, so I can easily replicate my computer experience on a new device, should I need to.

Most typically, you will want to set up your dotfiles in a way that you can create it as a repository on something like github. This is how the re-use is done; being able to pull it from a new computer.

There are many, very good guides out there on how to use dotfiles, and a good number of services and softwares too that can help make it easier to manage, such as stow, which I’ve lately been recommended.

I haven’t personally checked out stow nor do I have the need, because my dotfiles are in a good spot where they are.

I would highly recommend you check out this guide from Daytona, as it’s a good and thorough read on the matter. Additionally, my dotfiles repository have been heavily inspired from atomantic and webpro. I highly recommend you check those out and read through them.

But in all simpleness, the only thing you need to do is open up a new terminal window, navigate to your homefolder and create a new folder: $ mkdir dotfiles (or .dotfiles if you prefer).

And that’s it!

Wait a minute that isn’t going to do a whole lot, now is it?!

True enough. From having the folder in place there are several strategies you can choose in order to actually starting doing powerful things. I would recommend a simple approach like this:

  • Copy all your existing important configuration files into the newly created folder
  • From the appropriate locations, create symlink files that point to your dotfiles equivalent.
  • git init and commit your dotfiles to a git repository.
  • Optionally, you can include a README.md so you can leave some notes for yourself. After all, you wont be working on this file every day.

That’s effectively it! You now have a dotfiles repository, and you could go to any new device and pull your files down, create the symlinks and you would have the same configuration as on your current device!

Nifty, right?

Some extras to spice it up

While having a dotfiles repository in and of itself is probably a big step forward in making your device configuration consistent, there’s still a lot of room for improvement.

Especially in the realm of automation. The real power lies in not having to manually re-create symlinks or install this and that thing every single time, before things work.

If you glance over the photo of my repository, you will notice it has an install folder, which effectively contains a script that lets me fully automate setting up a new device.

Yes. You heard that right. The first – and only – thing I need to do when setting up a new device is do a git clone of this repo, and then run the install.sh script and voila.

It does everything. Configures my terminal, installs vscode, gets me my fonts, even installs homebrew and pulls down all the software and cli scripts I’m used to having access to.

It truly is magic.

That’s the thing about dotfiles, as with many other things in software development. You put in a bit of work up front, and you eliminate a ton of stress and inconvenience down the road. So while it does seem daunting, I think we can all agree that a few hours used now, is certainly better than a few hours used every time you get a new device. And let’s be honest, we all forget stuff, and there’s nothing worse than getting stuff because we forgot to configure a certain piece of software like a small dependency 🙂