DEV Community

Danny Kim
Danny Kim

Posted on

Sync Cursor Settings the Dotfiles Way

If you migrated from VS Code to Cursor, you might have noticed that Cursor doesn't support settings sync.

https://forum.cursor.com/t/sync-of-keybindings-and-settings/31

In this post, I'd like to share how to sync your Cursor settings & extensions the traditional way, similar to how you sync .zshrc and .vimrc files.

You put the settings file in a git repo.

Settings

Syncing your settings is simpler than syncing extensions, so let's start there.

What you need to do is:

  1. Save the settings.json file in a git repo.
  2. Clone the repo on your machine.
  3. Create a symlink to that settings.json file.

Git Repo Structure

Your repo should be structured like this if you're on Linux.

repo
└── cursor
    └── .config
        └── Cursor
            └── User
                └── settings.json
Enter fullscreen mode Exit fullscreen mode

And like this if you're on Mac.

repo
└── cursor
    └── Library
        └── Application Support
            └── Cursor
                └── User
                    └── settings.json
Enter fullscreen mode Exit fullscreen mode

Stow

You can use stow to create settings.json symlink in your home directory.
https://www.gnu.org/software/stow/

Install stow, and run this command from your repo root.

stow --no-folding -t ~ *
Enter fullscreen mode Exit fullscreen mode

Technically, --no-folding flag is optional, but I recommend you use it.

Once you run this command, your Cursor settings file is symlinked to the git repo. You can commit changes and push/pull.

Extensions

Syncing Cursor extensions is a little more complicated than syncing settings. Unlike settings.json, Cursor extensions are not saved as a text file. The extensions are saved as packages under ~/.cursor/extensions/.

What we have access to:

  • cursor --list-extensions command prints out the extension IDs that are currently installed.
  • cursor --install-extension <extension-id> command can install the extension.
  • cursor --uninstall-extension <extension-id> can do the opposite. Note: there's a bug that prevents you from uninstalling multiple extensions in one command.

From these ingredients, we can whip up a script that syncs extensions across machines.

  • Compare the mtime (last modified time) of the ~/.cursor/extensions/extensions.json file and the list file (more on the list file later).
    • (case 1) If the extensions.json file is newer, we generate a new list file. Dump the output of cursor --list-extensions command to [repo]/.cursor/extensions/list.txt.
    • (case 2) If the extensions.json file is older, then it means the extensions are outdated.
      • Get which extensions are currently installed by running cursor --list-extensions.
      • Install extensions that are not currently installed but exist in the list file.
      • Uninstall extensions that are currently installed but do not exist in the list file.

You can run this script manually or as a git post-merge hook.

Working Example

If you'd like to see how the extension syncing script is written, please check out my dotfiles repo.

https://github.com/0916dhkim/dotfiles/blob/b5f8558328ffe668750f94e2ab0afbc52eb3f6e7/post-merge.js (latest commit at the time of writing)

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.