Dotfiles
Making a Dotfile Repo
This method will allow you to sync dotfiles on different computers with a small amount of effort. You still have to pull down new changes as they occur on different machines, which sucks, but it is what it is. I'm sure there is a way I could set up git hooks to automate a check for if the local is out of date before syncing, but haven't done that yet.
- Create a new folder to keep your dotfiles (I use
$HOME/.dotfiles
). - Initialize a git repository there (
git init
). -
For each dotfile/folder you want to track/sync:
- Move it to your repo.
- Make a symlink to what you moved into the repo (
ln -s /path/to/moved/item
). - Test that the original path leads to the moved item (e.g. if syncing the
vimrc
file:cat ~/.vimrc
).
- Push the repo to the remote.
Different Settings on Different Computers
Shell RC Files
You can break out different files for different machines. If the file doesn't exist, it will skip sourcing that file.
For instance, treating your shell's rc file (e.g. zshrc
) as a global aliases file, we can source
other files that only pertain to our machines, like so:
.zshrc
#!/bin/zsh
source "$HOME/.home_zshrc"
source "$HOME/.work_zshrc"
Vim and Other Configs
In your shell's rc files, you can also set global environment variables that these external configs can use. For instance if you set an environment variable like COMP
to the name of whatever machine you are using, then other programs can read that and conditionally make choices based on that value.
For instance, to do this in your .home_zshrv
, use export COMP="home"
. Then in Vim, you could use a check to only set certain configurations, like tabs/spaces, etc.
if $COMP == 'home'
" do a thing
endif
References
Last modified: 202401040446