Use Chezmoi to guarantee idempotency of terminal

Wazaterm allows you to create a new terminal easily and simply. You can use dotfile’s management tool chezmoi (pronounced “chez-moi”) to save your time and effort for the initial setup.

Install chezmoi

Install chezmoi as described in the documentation with the following command.

$ sh -c "$(curl -fsLS git.io/chezmoi)"
info found version 2.7.5 for latest/linux/amd64
info installed . /bin/chezmoi

Chezmoi will be installed in $HOME/bin, so set the path. You can set it when you need it, or you can put the path in a .bashrc or something.

$ export PATH=/home/shohey1226/bin:$PATH 
or add the above line in .bashrc or the other rc files that you use.

Setup

The init command will create a directory.

$ chezmoi init
$ ls -al ~/.local/share/chezmoi
total 0

drwxrwxr-x 1 shohey1226 shohey1226 8 Nov 19 01:21 .
drwx------ 1 shohey1226 shohey1226 140 Nov 19 01:21 .
drwxrwxr-x 1 shohey1226 shohey1226 98 Nov 19 01:21 .git

Let’s register the files we need as soon as possible. If the file you want to register is a symbolic link, you can use --follow.

$ chezmoi add --follow .tmux.conf 
$ chezmoi add --follow .vimrc
$ chezmoi add .config/nvim/init.vim # this is a symlink to .vimrc. I'm sharing the config on neovim and vim8
# I'm using fish and back up entire directory
I'm sharing the config on neovim and vim8 # I'm using fish and back up the entire directory

If you register a file with a name starting with run_once, that file will be the first script to run.

$ chezmoi add run_once_install-packages.sh
$ head -n 10 .local/share/chezmoi/run_once_install-packages.sh                                                              
#! /bin/bash
sudo apt-get -y update
# nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39... | bash
. .nvm/nvm.sh
npm install yarn -g
$ chezmoi add run_once_install-setup.sh
$ cat .local/share/chezmoi/run_once_install-setup.sh
#! /bin/bash
git config --global user.email xxx
git config --global user.name "Shohei"

Then reflect it with apply and register it on github.

$ chezmoi apply
$ chezmoi cd
$ git add .
$ git commit -m "Initial commit"
# create dotfiles repo 
$ git remote add origin git@github.com:shohey1226/dotfiles.git
$ git branch -M main
$ git push -u origin main

One-shot setup in a new terminal

$ curl -fsLS git.io/chezmoi | sh -
$ . /bin/chezmoi init <a href="https://github.com/shohey1226/dotfiles.git">https://github.com/shohey1226/dotfiles.git</a>
$ chezmoi apply -v