Skip to content →

Dotfiles setup

Introduction

After spending quite a bit of time on developer machine setup, I found it time to version control and automate as much as possible. Especially since I work on two different machines, I needed an easy way to synchronize the setup. Ideally, I would look into something like Nix, but one step at a time: first, manage the dotfiles.

Dotfiles

Dotfiles are configuration files for various programs and tools in Unix-like operating systems, e.g., Mac. They are named with a leading dot (.) to hide them in directory listings by default. These files typically contain user-specific settings and preferences for command-line interfaces, text editors, version control systems, and other software. Some examples are:

  • .vimrc
  • .gitconfig
  • .tmux.conf

We can bring these files under source control for easier environment replication. Here is an example from the .vimrc file:

set mouse=a
set number
set tabstop=2
set shiftwidth=2
set expandtab
set relativenumber
set spell
syntax on

Symlinks

Symbolic links, also known as symlinks or soft links, are special types of files that act as references or pointers to other files or directories. They are similar to shortcuts in Windows but more powerful and flexible. Symlinks allow you to:

  • Create multiple access points to a single file or directory
  • Organize files more efficiently without duplicating data
  • Maintain compatibility with applications expecting files in specific locations

In managing dotfiles, symlinks are often used to link configuration files from a version-controlled directory to their expected locations in the home directory, making it easier to manage and sync settings across different machines.

I created in my dotfiles repo a small script that sets up symlinks to the files in the repo in the expected places:

ln -sf ~/dotfiles/.zshrc ~/.zshrc
ln -sf ~/dotfiles/.gitconfig ~/.gitconfig
ln -sf ~/dotfiles/.tmux.conf ~/.tmux.conf
ln -sf ~/dotfiles/.vimrc ~/.vimrc

The repo is expected to be checked out in the ~/dotfiles directory. However, this can easily be changed.

GitHub Codespaces

GitHub Codespaces is a cloud-based development environment that allows developers to write, run, and debug code directly from their browser. It is built on the devcontrainer technology. Codespaced supports automatically installing dotfiles from a repository of choice. The repo does not need to be called dotfiles, however the name makes it selfexplanatory. Go into your GitHub profile setting and tick off the box:

Conclusion

In conclusion, managing dotfiles through version control and automation is a powerful way to streamline your development environment setup and maintenance. By using a combination of Git repositories, symlinks, and tools like GitHub Codespaces, you can easily replicate your preferred settings across different machines and cloud environments.

Published in GitHub productivity programming tips&tricks

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x