Growing with the Web

Synchronising Visual Studio Code extensions

Published
Tags:

With the new command line arguments allowing installation and removal of extensions becoming available in the latest version of VS Code, it is now possible to automate extension syncing relatively easily.

Version 1.2.0 of VS Code landed in the Stable channel on Monday the 6th of June and brought the following new command line args to code:

code --list-extensions
code --install-extension <extension>
code --uninstall-extension <extension>

These finally allow an official mechanism to script extension installs, making it easier to maintain a consistent development environment across machines. This is the bash script I use to install a set of extensions to both the stable and insiders channels of VS Code. It should work on Linux, OS X and Windows (using git bash or something similar)

EXTENSIONS=(
  "cssho.vscode-svgviewer" \
  "dbaeumer.vscode-eslint" \
  "EditorConfig.EditorConfig" \
  "ryzngard.vscode-header-source" \
  "spywhere.guides" \
  "Tyriar.sort-lines" \
  "Tyriar.lorem-ipsum" \
  "waderyan.gitblame"
)

for VARIANT in "code" \
               "code-insiders"
do
  if hash $VARIANT 2>/dev/null; then
    echo "Installing extensions for $VARIANT"
    for EXTENSION in ${EXTENSIONS[@]}
    do
      $VARIANT --install-extension $EXTENSION
    done
  fi
done

To customise this just replace the contents of the EXTENSIONS variable at the top with the IDs of your own preferred extensions. The easiest way to get the extension IDs is by installing the extension locally and running code --list-extensions. They can also be retrieved from the marketplace URL.

The itemName query parameter is set to the extension ID

Comments

comments powered by Disqus
Like this article?
Subscribe for more!