One of my favorite tools is VSCode. I like it’s versatility, the fact that I can use it with any language (that I use, anyway :)) it’s something I really like. As much as I like VSCode there is one thing I dislike doing, and that is, installing the extensions on a new VM or machine! Because I often spin up machines for testing, I wanted to see if there was a way to automate this.
In my quest for a great VSCode hack, I found that VSCode supports cli and you can install the extensions via the command line using the code ‘code –install-extension ’ command. The caveat is that it can only take one argument at a time. Then I thought about making a script, but...wait for it....Stack Overflow to save the day! That's right I found one in an answer before I even got started writing it. I modified the scripts to take a file containing the extension names as an argument.
To backup your current extensions to feed it to the script use the command:
code --list-extensions > VSCode_Extension_List.txt
Here is the script snippet for Linux:
#!/usr/bin/env bash
cat $1 | while read extension || [[ -n $extension ]];
do
code --install-extension $extension --force
done
Here is the script snippet for Windows using PowerShell:
Get-Content $args[0] | ForEach-Object {code --install-extension $_}
I hope you find this useful, makes you a little happier and that it saves you some time!
Top comments (0)