Prerequisite
Setup
Create a new directory in your $HOME. Call it dotfiles.
mkdir ~/dotfilesInitialize a Git repo in the dotfiles directory.
cd ~/dotfiles
git initYou can sync this repo to GitHub.
Adding Files
Move the file into ~/dotfiles, then create a soft link back to it’s original location.
mv ~/.zshrc ~/dotfiles/
ln -sf ~/dotfiles/.zshrc ~/.zshrcRemoving Files
Remove the symlink, then move it’s ~/dotfiles equivalent into it’s proper place.
rm ~/.zshrc
mv ~/dotfiles/.zshrc ~/.zshrcDeploy on a New Machine
This process is called “bootstrapping”.
Clone the repo, then soft link the files manually.
cd ~
git clone https://github.com/username/dotfilesThen manually soft link the files to their locations.
rm ~/.zshrc
ln -sf ~/dotfiles/.zshrc ~/.zshrcBonus
Make this process easier with a few scripts.
Add File Function
Source this script and
### dotfiles/manage_file.sh ###
DOT_PATH=~/dotfiles
dot_add() {
mv $1 $DOT_PATH/
ln -sf $DOT_PATH/$1 $1
}
dot_rm() {
rm $1
mv $DOT_PATH/$1 $1
}Bootstrapper Script
You can write a script to bootstrap your dotfiles automatically.
### dotfiles/bootstrapper.sh ###
# zshrc
ZSHRC_PATH=.zshrc
rm ~/$ZSHRC_PATH
ln -sf ~/dotfiles/$ZSHRC_PATH ~/$ZSHRC_PATH
# alacritty
ALACRITY_PATH=.config/alacritty/alacritty.yml
rm ~/$ALACRITTY_PATH
ln -sf ~/dotfiles/$ALACRITTY_PATH ~/$ALACRITTY_PATH
...