Skip to content

Instantly share code, notes, and snippets.

@searls
Created June 20, 2019 18:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save searls/ae8e35a1403700cccb76e0179d240308 to your computer and use it in GitHub Desktop.
Save searls/ae8e35a1403700cccb76e0179d240308 to your computer and use it in GitHub Desktop.

Here's a neat trick.

I treat my git clones as disposable between computers, but keep my project-specific dotfiles (usually containing environment variables, individual configurations, and so on) synced across devices in iCloud. Then, this script is just a matter of adding symlinks for each of the dotfiles I've saved for each of my projects to each of their clones.

So if my dotfiles are saved like this:

$ tree -a ~/icloud-drive/dotfiles/project-dotfiles/
/Users/justin/icloud-drive/dotfiles/project-dotfiles/
├── searls
│   ├── fine_ants_app
│   └── searls.github.com
│       └── .rgignore
└── testdouble
    ├── scheduled-merge
    │   └── .env
    └── testdouble.js
        ├── .projections.json
        ├── .rgignore
        └── .vimrc

And my repos are organized symmetrically:

$ tree -a ~/code
/Users/justin/code/
├── searls
│   ├── fine_ants_app
│   └── searls.github.com
└── testdouble
    ├── scheduled-merge
    └── testdouble.js

Then I can run project-dotfiles-link, at any point and it'll make sure each of those working copies have links to my synchronized dotfiles.

#!/usr/bin/env bash
# necessary because project-specific dotfiles will almost always match a global
# or project-level gitignore, so we need to make sure we add them by force here
git add --force "$ICLOUD_DRIVE/dotfiles/project-dotfiles"
git status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment