Automation using dotfiles

27. July, 2020 6 min read Develop

Start hacking in just a few hours

It's a beautiful, warm and sunny day outside. You are longing for your after-work beer to enjoy the rest of the day. But there is this super important project that's due by the end of the week and it's just 10 in the morning. Suddenly a wild hardware failure appears and you are out of pokeballs to solve the problem and safely continue.

Your computer doesn’t boot up anymore. You are hurrying to the next hardware store to get a replacement. Sitting through the setup or restore process takes a lot of time and you still have to set up the project as well to continue your work. It’s the end of the day. 😠

In fairness, such a scenario does not happen that often, ideally. Though setting up a computer can be time-consuming. On top of that, all the little tweaks and settings that have been made over the years cannot easily be restored.

Dotfiles to the rescue

I first encountered the concept of dotfiles about 8 years ago. I was automating the installation of multiple macOS workstations through scripts that were executed on the host system. osx-bootstrap, a collection of simple bash scripts, was my attempt to solving that problem.

In essence, dotfiles are no different from the solution way back. They are a collection of scripts that run on certain conditions. Their power is only limited by your know-how of the environment/system. They can configure your entire system automatically, update apps and run maintenance scripts.

This inspired me to create my dotfiles. Their purpose is to shift my entire systems configuration into little neat shell scripts. Now, I can update and configure my machine with ease and without hassle.

So if my computer decides to go to Valhalla, I simply get a new one, run the scripts and I’m ready to go. Sadly, the scripts do not automate the actual work yet ¯\_(ツ)_/¯.

How to get started

I highly recommend to fork and review the code first, before giving my dotfiles a try. In theory, they can be installed on an existing system as well, but a fresh installation is recommended.

To get started, follow the installation instruction in the readme. After a successful installation you should be able to run the following command in a terminal:

dot --help

This lists all currently available commands that can be run. The options currently are:

  • dot --install runs the installation process again. It’s intentional that this can be run again, as you make changes to the dotfiles yourself, certain installation actions need to run again.
  • dot --update runs the update process. This should ideally be run regularly as it runs version updates on several packages.
  • dot --edit opens the dotfiles directory in your favourite editor so you can start hacking and adapting as fast as possible.

More functionality might be added in the future or add yours inside bin/dot. It’s also helpful to run alias in the terminal to see all available shorthand commands. Dotfiles normally add a bunch of them to your system.

Running my dotfiles in a shell through "dot --update"
Running my dotfiles in a shell through "dot --update"

What’s the structure like

I decided to follow a modular pattern in my dotfiles. I didn’t want to spend much time figuring out where to make changes or add new features. Especially if I just discovered a new configuration/feature to integrate.

As such, each folder contains its own independent logic/topic without much cross-linking. There are other patterns around. If you are interested, check out my credits section on GitHub with links to other repositories for inspiration.

There are exceptions I’d like to highlight though:

  • bin/ stores binary files that are added to the system $PATH automatically. If you want to create your scripts, simply add them there.
  • macos/ and linux/ contain system-specific configurations.
  • scripts/ holds the main install and update scripts that include other modules.
  • utils/ contain utility variables and functions that are used throughout the dotfiles.

In addition to that, most folders implement an install and update file that handle the respective install/update tasks. Even though most operations are almost identical (and some could be merged), I still prefer the separation of context for better organisation 📁.

What’s included

The dotfiles contain my flavour. As such, the tools used are tailored to my workflow. You might not agree and want to use alternative options. That being said, let me highlight some of the features included:

  • The zsh/ module automatically loads every aliases.zsh, paths.zsh and functions.zsh from other modules. This breaks the independence of that module but is a necessary design decision to keep maintainability.
  • The system/ module also breaks that chain by creating symlinks of every *.symlink file into the users home directory ~/.... This is very helpful to keep configuration scripts, such as .gitignore or zshrc, inside the dotfiles.
  • The fonts/ module installs the most used fonts into your system. Gone are the days of looking for your CI/CD fonts.
  • The git/ module automatically configures your git settings and even helps set up a GPG key.
  • The homebrew/ module installs common packages and applications without downloading them manually from every website.
  • The node/ and python/ modules configure my respective node and python environments to start hacking.
  • The tmux/, vim/ and vscode/ modules setup my development environment and editors.

There is also a hidden private/ folder that holds scripts, that should not be public. I backup these settings through “Mackup” to my iCloud drive. The module holds scripts for my morning routine, our standup (opening google meet, load standup board, share screen, set do not disturb mode etc.) and other work-related automation.

Simply automate your monotonous tasks and let the computer do the heavy lifting 🏋️.

Conclusion

Dotfiles are very powerful. With the right know-how, you can increase your productivity very efficiently. Though, it also requires an initial time investment setting everything up and then maintaining them. Your dotfiles evolve, as such, they are never finished. You gain knowledge and expertise that change your flow or tools. You may switch jobs and your expectations from the dotfiles are suddenly different.

My dotfiles are still very much focused on macOS. I’m playing around using Linux/Manjaro on a separate partition. The support for Mac hardware is very limited and several manual configurations are required. So it feels natural to incorporate them into my dotfiles.

I’d like to write a separate blog post about that adventure in the future 😉