Why?

Ever set up a new laptop (or desktop)? If you've done any significant customization to your shell environment over the years, it's a pain to find and copy those changes over. If you want to maintain the same environment over a long time and change out your hardware more easily, this can help. Just link to your files on a new machine and you're good to go.

This could also be helpful if you regularly work on multiple Macs and want to keep your changes in sync. Maybe between your home and work computers.

How?

Using the configuration file for the ZSH shell, here's an example.

On your original (old) computer

This is just a shortcut to make the iCloud folder easier to remember/type, so feel free to skip this if you want and use the full path every time instead. I find the full path a bit cumbersome.

ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs ~/iCloud

Move your config file to iCloud

Copy the configuration file you want to have in the cloud from your home folder to your iCloud folder.

cp ~/.zshrc ~/iCloud/.zshrc

Stop using your old configuration file and link to the file you copied to iCloud instead.

mv ~/.zshrc ~/.zshrc-backup
ln -s ~/iCloud/.zshrc ~/.zshrc

Alternatively, you can remove the original configuration file with rm instead.

On your new computer

Create a shortcut that links to your iCloud folder. Again, this is just to make things easier, so feel free to skip this if you know what you're doing.

ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs ~/iCloud

Back up the original configuration file and link to the file in iCloud.

mv ~/.zshrc ~/.zshrc-backup
ln -s ~/iCloud/.zshrc ~/.zshrc

Alternatively, you can remove the original configuration file with rm instead.

Example with multiple files, using a folder in iCloud Drive

I've put my dotfiles into a terminal folder inside my iCloud directory, so this is my current setup script:

mv ~/.zshrc ~/.zshrc-backup
mv ~/.gitconfig ~/.gitconfig-backup
mv ~/.gitignore_global ~/.gitignore_global-backup
mv ~/.gemrc ~/.gemrc-backup
mv ~/.nanorc ~/.nanorc-backup
mv ~/.pryrc ~/.pryrc-backup
mv ~/.env ~/.env-backup

ln -s ~/iCloud/terminal/.zshrc ~/.zshrc
ln -s ~/iCloud/terminal/.gitconfig ~/.gitconfig
ln -s ~/iCloud/terminal/.gitignore_global ~/.gitignore_global
ln -s ~/iCloud/terminal/.gemrc ~/.gemrc
ln -s ~/iCloud/terminal/.nanorc ~/.nanorc
ln -s ~/iCloud/terminal/.pryrc ~/.pryrc
ln -s ~/iCloud/terminal/.env ~/.env

After confirming that everything is working correctly, I remove the backup files:

rm ~/.zshrc-backup
rm ~/.gitconfig-backup
rm ~/.gitignore_global-backup
rm ~/.gemrc-backup
rm ~/.nanorc-backup
rm ~/.pryrc-backup
rm ~/.env-backup