Manually copying VS Code extensions
The other day, I found myself needing to import my Extensions from one instance of VS Code to another.
"Why not use Settings Sync?!"
Well, one instance is my work laptop and the other is personal and I am not able to sync to a personal account from a work machine.
What I can do, is use a USB memory stick!
How do I achieve this wizardry?!
On the machine with the extensions you want to copy. For me, this is my work Mac…
code --list-extensions | xargs -L 1 echo code --install-extension > _extensions.sh
Now, put _extensions.sh
onto a pen drive, upload to the cloud - basically get it somewhere your other machine can access it.
On your other machine - for me this is my personal laptop;
- Open terminal/iTerm/Warp/whatever
- Navigate to the folder with the
_extensions.sh
file in it. This does not need to be anywhere near your VS Code installation - it could still be in your Downloads folder or whereever. - Run the command
bash _extensions.sh
- Watch in amazement as VS COde installs each of your extensions from your old machine!
How does this work?!
If you're the kind of person who doesn't like copy-pasting bash
commands into your terminal without know what they do in detail, read on!
code # The CLI for VS Code
--list-extensions # Lists the installed extensions for the instance of VS Code
| # Pipes the list as an array
xargs # Takes the piped array and creates a command from it
-L 1 # Basically tells xargs to treat line-ends as a new command
echo # The command to "write" or "print" the `code --install-extension > _extensions.sh` text
code # See above
--install-extension # Installs the named extension
> # Indicates the preceeding text is written _into_
_extensions.sh # The filename to be written to
Conclusion
While Settings Sync is probably the best way to handle the syncing of Extensions there are sometimes situations where it isn't feasible. Knowing how to do this programatically instead of making a manual list of the extension names and installing them one-by-one is a useful tool in your arsenal.
I hope this helps someone else 😎
Fin
Cover image courtesy of Hello I'm Nik.
onward-journeys module
Real. Simple. Syndication.
Get my latest content in your favorite RSS reader.
I use InoReader but you don't have to.
Comments
In almost all cases, the comments section is a vile cesspool of Reply Guys, racists, and bots.
I don't want to have to deal with that kind of hell so I don't have a comments section.
If you want to continue the conversation, you can always hit me up on Mastodon (which is not a vile cesspool of Reply Guys, racists, and bots).