- Published on
Manage your dotfiles with yadm
- Authors
- Name
- Bart Louwers
- @bartlwrs
Power users of UNIX-based operating systems tend to accumulate dotfiles, scripts
and other files that are essential for setting up their development machines for
maximum productivity. With all the effort put into this, it is a very good idea
to have all these files comfortably checked into version control, ready to be
installed on a new device or kept in sync across devices. There is a really
useful tool called Yet Another Dotfiles Manager (or
yadm
) that will help you do exactly that.
One of the greatest things about yadm
is that it has the same interface as
git
. If you know git
, you already know how to use yadm
. Take a look at the
Getting Started guide to check this
yourself. In a nutshell, with yadm init
you set up a repository for yadm
to
use. You can add files to this repository from anywhere within your home
directory (using yadm add
). Using yadm commit
you can stage changes and you
can push them with, you guessed it, yadm push
. Now when you run yadm clone
on another device the files you added will be installed on the same locations as
where you added them.
Scripts
Aside from managing configuration files, I find it also very useful to manage
assorted personal scripts in ~/bin
. I have added PATH=$HOME/bin:$PATH
to my
~/.bashrc
(a dotfile that is of course also managed). When I add or change a
script, it is a few commands away from being available on all my devices, with
all benefits of version control on top for free.
Bootstrap
You don't have to do all setup and configuration using dotfiles, sometimes you
may want to (or have to) use a script. You can create a so-called
bootstrap script at ~/.config/yadm/bootstrap
that is then run every time you install your dotfile repository on a new
machine. It can also be manually run using yadm bootstrap
.
For example, instead of committing ~/.gitconfig
, I have added these commands
to my bootstrap script:
git config --global init.defaultBranch main
git config --global alias.sync "!git commit --allow-empty-message --no-edit && git push"
That last command allows me to use git sync
(or yadm sync
) to make a commit
with an empty message, and push it instantly. Don't worry, I don't use this
power for shared repositories!
As another example, I also use my bootstrap script to set the same default applications across machines:
xdg-mime default org.gnome.Nautilus.desktop inode/directory
xdg-mime default org.gnome.Evince.desktop application/pdf
xdg-mime default calibre-ebook-viewer.desktop application/epub+zip
I even create a symlink to the bootstrap script itself inside the bootstrap script for easy access:
if [[ ! -f ~/bootstrap ]]; then
ln -s ~/.config/yadm/bootstrap ~/bootstrap
fi
Knowing that my personal (configuration) files are stored in version control and
will not get lost has certainly motivated me to put a lot more care into them.
If you are not storing your dotfiles in version control, I can highly recommend
trying it out. You can start with just your personal scripts
or just your ~/.bashrc
and expand your dotfile imperium as you go.