VSCode Recommended Extensions Script
We saw in the post we can use .vscode/extensions.json
for workspace base
extension recommendation. Ok but how we can generate this file in a developer
way?
For a starting point, if you can look at the doc Manage Extensions, you can see that you can list your extensions by:
$ code --list-extensions
0. Generate extensions.json script
#!/bin/bash
VSC_DIR="$PWD/.vscode"
EXTENSION_JSON="$VSC_DIR/extensions.json"
EXTENSION_LIST="$VSC_DIR/extensions.list"
TMP_FILE="$VSC_DIR/extensions-tmp.list"
echo "Copying Code extensions"
mkdir -p $VSC_DIR
cd $VSC_DIR
code --list-extensions > $EXTENSION_LIST
cp $EXTENSION_LIST $TMP_FILE
sed -i 's/.*/\t\t\"&\",/' $TMP_FILE
echo \
'{
// See http://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
//user extensions
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
]
}' > $EXTENSION_JSON
sed -e '/user extensions/ {' -e 'r extensions-tmp.list' -e 'd' -e '}' -i $EXTENSION_JSON
rm $TMP_FILE
cd $PWD
echo "Code extensions copied."
With above script it basically does 2 things:
- Create
.vscode
andextensions.json
&extensions.list
files, - Echo your extensions into these files with right formats.
1.0 Install extensions in GUI
If you put your .vscode/extensions.json
in your project root, after you open
your workspace with VSCode it will ask you:
1.1 Install extensions in cli
In the doc Manage Extensions we also see there is another flag option to allow us to install extensions:
$ code --install-extension
OK, how we can use this with our generated extensions files? With some magic bash for sure:
$ cat .vscode/extensions.list | xargs -L 1 code --install-extension
Extra
If you want to see my extensions go to: My VSCode Extensions. Also you can check out my whole VSCode backup: My VSCode Backup
All done!