I'm using most recommended method of managing dotfiles on mac by using stow. e.g., https://alexpearce.me/2016/02/managing-dotfiles-with-stow/
I found that it works great and does what I need to if I'm doing a clean install. I have a folder structure that looks like this inside my ~/dotfiles folder
.
├── install.sh
└── zsh
└── .zshrc
when I run
stow zsh
It correctly sets the symlink in place from ~/.zshrc
.zshrc -> dotfiles/zsh/.zshrc
Problem however is if .zshrc is already present in the home folder, then stow will not override it with symlink. Instead it will just throw and error.
WARNING! stowing zsh would cause conflicts:
* existing target is neither a link nor a directory: .zshrc
All operations aborted.
I understand I can manually "rm ~/.zshrc" file before running stow and will work.
I'm trying to see if there is cleaner way of setting up symlinks without having to manually run rm command for all the existing dotfiles.
Assuming you have the dotfiles in a Git repository and that you have committed the current changes, you can use this "trick": stow provides this option:
By looking at the man page (https://www.gnu.org/software/stow/manual/html_node/Invoking-Stow.html):
So, assuming
~/.zshrc
is an existing file, and you have~/dotfiles/zsh/.zshrc
, you run (instead ofstow zsh
, which would cause a conflict):This will replace your
~/dotfiles/zsh/.zshrc
with the contents of the existing~/.zshrc
and will create the link:Now, you just need to restore your
dotfiles/zsh/.zshrc
, e.g., withgit --reset hard
.In fact, the manual also says: