Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Last active March 30, 2023 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tos-kamiya/f426671c2ad991e1568263c3155c069b to your computer and use it in GitHub Desktop.
Save tos-kamiya/f426671c2ad991e1568263c3155c069b to your computer and use it in GitHub Desktop.
cli tool to update vscode extensions
#!/usr/bin/env bash
# Temporary files for storing the list of extensions
tempfile1=$(mktemp)
tempfile2=$(mktemp)
# Save versions of extensions before the extension update process
code --list-extensions --show-versions > "$tempfile1"
# Print a message to indicate that the extension update process starts
printf "[INFO] start: vscode extension updating."
sleep 0.5
# Define a spinner animation
spiner_figs='-\\|/'
spiner_i=0
# Loop over the list of extensions and update each one
for ext in $(code --list-extensions)
do
# Print a message to show an extension being updated
spiner_i=$(( (spiner_i+1)%4 ))
printf "\33[2K\r"
printf "[INFO] (${spiner_figs:$spiner_i:1}) try updating: $ext"
# Try to update the extension
code --force --install-extension "$ext" > /dev/null
done
# Print a message to indicate that the extension update process has completed
printf "\33[2K\r"
echo "[INFO] done: vscode extension updating."
# Identify and show which extensions have been updated
code --list-extensions --show-versions > "$tempfile2"
git diff --no-index -U0 "$tempfile1" "$tempfile2" | tail -n +5 | grep -v '@@'
# Clean up the temprary files
rm -rf "$tempfile1"
rm -rf "$tempfile2"
# ref: https://github.com/microsoft/vscode/issues/56578#issuecomment-554025719
@tos-kamiya
Copy link
Author

tos-kamiya commented Mar 26, 2023

If you have a lot of VSCode extensions installed (like me), do you get a "reload required" every time you open VSCode?
This could be a particular annoyance if you are using an integrated package management tool.
I have solved such frustrations by running this script immediately after an integrated package management tool (namely, topgrade).

@tos-kamiya
Copy link
Author

(Some people have said the same thing to the VSCode developers, but for whatever reason they don't seem to be in the mood to be proactive about it.)

@tos-kamiya
Copy link
Author

A screenshot. You can see the warning messages output by the VSCode update command. You can also see that the tool enumerates the changes in the version of the plugin at the end of the update.
Screenshot from 2023-03-30 12-31-46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment