- git
- python
- code (cli of VSCode)
All reachable from the PATH of the system
-
Using the portable version of VS Code, there is a
/data/
folder in the software's directory -
This
/data/
folder will be the repository. So, initialize it withgit init
$ git init
OBS:
A normal installation (not portable) may work as well. But then, the folder with settings is located in%APPDATA%\Code\User\
(Windows system). The advantage in using the/data/
folder of a portable installation is the access to theextensions
folder in the same directory. This folder is in a different default location in a normal installation (%USERPROFILE%\.vscode\extensions\
in Windows system), which can be changed with the--extensions-dir
command line option (See the docs) -
Add manually any files you want. Normally, we want to sync files from the
user-data/User/
folder:$ git add user-data/User/keybindings.json $ git add user-data/User/settings.json $ git add user-data/User/snippets/javascript.json ...
But it could be also any files from the
/extensions/
folder, or the root folder (/data/
) as well. -
Create an empty text file
extensions.txt
and add it to git$ touch extensions.txt $ git add extensions.txt
-
Put this python script on the repository's root folder (i.e. the
/data/
folder) and add it to git$ git add syncextensions.py
Obs:
In the line 3 of the script, you can configure the listignoreextensions
with extensions IDs you don't want to sync. -
Ignore everything else and add the
.gitignore
file to git$ echo "*" > .gitignore $ git add -f .gitignore
-
Now, create the remote repository on GitHub, add the remote, commit and push to it.
$ git remote add origin <remote-url> $ git commit -m "first commit" $ git push --set-upstream origin master
-
Configure these two keybindings on
keybindings.json
{ "key": "ctrl+shift+alt+d", "command": "workbench.action.terminal.sendSequence", "args": { "text": "python -c \"import os; os.chdir(os.path.dirname(r'${execPath}') + r'\\data'); os.system('git pull'); os.system('python syncextensions.py')\" \u000D" } }, { "key": "ctrl+shift+alt+u", "command": "workbench.action.terminal.sendSequence", "args": { "text": "python -c \"import os; os.chdir(os.path.dirname(r'${execPath}') + r'\\data'); os.system('python syncextensions.py & git status & git commit -am sync_settings & git push')\"\u000D" } }
-
Done. Now, the keybinding ctrl+shift+alt+d will download the synced settings from the remote repository and the keybinding ctrl+shift+alt+u will upload the settings to the remote repository.
-
The first time you execute the command, it will prompt for uninstall every extension, since the
extensions.txt
file is empty. Just answer "no" to all of them. From the second time on, it will have the extension list. -
You can change the commit message for push or leave it empty (removing the
-m
argument) to insert a different commit message in every push. You can also edit the local repository by adding new files.