Dotfiles

I briefly mentioned dotfiles in my last blog post. In this post, I want to go a bit deeper into dotfiles. We will also talk about using stow for symlinks.

Dotfiles

Dotfiles are configuration files that are hidden and start with a dot. These files (if there are no saved passwords) can be stored in a git repository and can be cloned on any machine. One of the use case is having the same setup / configurations across multpile machines

Dotfiles typically resides in the user home folder. If you want to version control these, you will have to make your home folder a git repo and use .gitignore to ignore all files other than the specific files of your interest. This is how I started. Then I found a solution using stow, where the files could be anywhere on the machine, and I can create a symlink for these files and folders to the required location (home in this case)

Stow

A symlink is a symbolic Linux/ UNIX link that points to another file or folder on your computer, or a connected file system. This is similar to a Windows shortcut. Stow is a symlink farm manager which takes distinct packages of software and/or data located in separate directories on the filesystem, and makes them appear to be installed in the same place. You can use stow to create symlinks for your dotfiles. You can read more about stow here and here

Install stow with:

brew install stow

Creating Dotfiles Repository from sctarch

The simple use case where you are creating all the required files is shown in the last blog. Let us take a look at a case where we have git submodules. I am using the example of Tmux where I am using sub modules from other git repos

  1. Create a git repository on github called dotfiles
  2. Clone the repository to your local machine git clone <repo-url>
  3. Change directory to dotfiles cd ~/dotfiles
  4. For Tmux
    1. Create a folder called tmux mkdir tmux
    2. Change directory to tmux cd tmux
    3. Move the tmux.conf file to tmux folder mv ~/.tmux.conf .
    4. Add a tmux plugin (tpm is shown for example only)
      1. mkdir .tmux/plugins
      2. cd .tmux/plugins
      3. git submodule add https://github.com/tmux-plugins/tpm
    5. Move to dotfiles folder cd ../../..
    6. Create a symlink for tmux stow tmux
  5. Check git status git status
    1. You will find a new .gitmodules file and a tpm in the repo
    2. Note that tpm is a submodule
  6. Add and commit the changes git add . && git commit -m "Basic dotfiles setup"
  7. Push the changes to a remote repository git push

Reusing the Dotfiles repository on a new machine

  1. Clone the dotfiles repository git clone --recurse-submodules <repo-url> ~/dotfiles
  2. Change directory to dotfiles cd ~/dotfiles
  3. Create a symlink for tmux stow tmux