How I Build, Maintain and Use My ~/.dotfiles


Hello friends,

Today, we’re diving into the world of dotfiles.

If you’ve ever customized your terminal, text editor, or shell, you’ve likely encountered the concept of managed dotfiles. Let’s explore why managing these configuration files is essential, how to handle them locally with stow and symlinks, and how to sync them remotely to a remote dedicated machine we create using Coder.

What Are Dotfiles?

Dotfiles are a collection of configuration files that allow you to configure applications using code. They get their name from the Unix convention of hiding files by prefixing them with a dot, such as .zshrc, .bashrc, .vimrc, etc. These hidden files store your custom settings and preferences, enabling you to tailor your environment to your liking.

Why Manage Dotfiles?

  1. Recoverability: If something goes wrong with your machine, having your dotfiles backed up means you can quickly recover your configuration.
  2. Portability: Easily configure other working environments using your dotfiles. Simply clone your repo and you’re set.
  3. Version Control: By using Git, you can maintain a history of changes made to your configuration files. This acts as a series of “snapshots” that you can revert to if needed.

Managing Dotfiles Locally with Stow and Symlinks

Using stow, a Unix command to manage symlinks, helps you keep a separate repo that links specific configuration files to the $HOME/.config directory.

This method allows you to manage only the apps you care about, without committing and pushing your entire .config directory publicly.

Organize Your Dotfiles: Create a directory structure for your dotfiles. Each configuration should have its own folder. Ideally, run git init and make this a git repository. You can checkout mine here:

dotfiles/
├── bash/
│ └── .bashrc
├── vim/
│ └── .vimrc
└── git/
└── .gitconfig

Use Stow to Create Symlinks: Navigate to your dotfiles repo and run Stow to create symlinks in your home directory:

stow --target ~/.config .

Working with a .stowrc File

To improve the process above, let’s customize Stow’s behavior, you can use a .stowrc file to ignore certain files and configure the target directory for Stow. Here’s my .stowrc that’s pushed to my repo:

--target=~/.config
--ignore=.stowrc
--ignore=DS_Store

Syncing Dotfiles Remotely with Coder

Coder (coder.com) provides cloud-based development environments, perfect for maintaining consistency across your devices. Here’s how to sync your dotfiles with Coder.

Coder got templates for pretty much every option you can think of, including syncing your dotfiles repo to an instance you provision with them.

To use their dotfiles template all you have to do is add startup_script under resource "coder_agent" "main" like so:

resource "coder_agent" "main" {
startup_script = coder dotfiles -y https://github.com/<myname>/dotfiles
}

If you’re subscribed to DevOps ToolBox on Youtube there’s a video coming out soon going through this entire process step by step!


Hopefully this helped you come up with ideas behind the reasoning and application of my flow to improve yours.

While I know this can be improved with projects like chezmoi, or Nix’s home manager, I’m really curious to hear your thoughts! Please reply to this email with feedback / ideas and let’s chat!

Until next week, have a great reset of your day.

Whenever you’re ready, here’s how I can help you:

ESPRESSO FRIDAYS

Every once in a while I send hand picked things I've learned. Kind of like your filter to the tech internet. No spam, I promise!

Read more from ESPRESSO FRIDAYS

Hi friends, Tmux is a fantastic tool for managing terminal sessions, but it has its limitations. One major drawback is the lack of a floating pane feature, which can make navigating between different panes cumbersome and inefficient. Me frustrated with Tmux lack of floating panes while Zellij is killing it... Most users workaround this by creating new Tmux windows or panes, or by using hidden splits to zoom in and out. These methods work but can be inefficient and require many keystrokes,...

My Neovim takes roughly 113ms to fire up. THIS IS FAST. However, I don’t lazy load anything. Being a Lazy.nvim user, it’s kind of a shame I’m not actually making use of my plugin manager's flagship feature. But then again, it takes 113ms for nvim to start, what is there to gain here? Let’s say I drop it to 50ms. I gained 60ms which means that if I’m going to spend 30 minutes to actually reduce it, I’d have to open Neovim 15,929 times to get my time back 🤣. With an average of probably 5 times...

Hi Friends! Curious about Nix? Me too. The past few months of exploring it were quite interesting, to say the least. And it still feels like I've barely scratched the surface. [TL;DR] That said, it's already replacing some of my old workflows and I'm really happy discovering it, even while not even using Linux for most of my local work. What’s Nix? Nix is a powerful suite of tools, including a package manager (Nixpkgs), language (Nix DSL), and operating system (NixOS). It provides a robust...