Forked from 3v1n0/vscode-unused-workspace-storage-cleanup.sh
Last active
February 5, 2021 16:56
-
-
Save akunzai/1f4ff6e9859f4134eaa1ffcd7bb144af to your computer and use it in GitHub Desktop.
VSCode unused workspaceStorage cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://code.visualstudio.com/docs/getstarted/settings#_settings-file-locations | |
case "$(uname -sr)" in | |
Darwin*) | |
VSCODE_HOME="$HOME/Library/Application Support/Code/User" | |
;; | |
Linux*WSL*) | |
# https://github.com/wslutilities/wslu | |
if hash wslvar 2>/dev/null; then | |
VSCODE_HOME="$(wslpath "$(wslvar APPDATA)")/Code/User" | |
else | |
VSCODE_HOME="/mnt/c/Users/$USER/AppData/Roaming/Code/User" | |
fi | |
;; | |
Linux*) | |
VSCODE_HOME="$HOME/.config/Code/User" | |
;; | |
*) | |
echo "ERROR: Unsupported OS" | |
exit 1 | |
;; | |
esac | |
OIFS="$IFS" | |
IFS=$'\n' | |
for wsJson in $(find $VSCODE_HOME/workspaceStorage -maxdepth 2 -type f -name workspace.json); do | |
folder="$(python3 -c "import sys, json; print(json.load(open(sys.argv[1], 'r'))['folder'])" "$wsJson")" | |
if [[ $folder == file://* ]]; then | |
if hash wslpath 2>/dev/null; then | |
folder="$(wslpath "$(echo "$folder" | sed 's#^file:///##;s/+/ /g;s/%\(..\)/\\x\1/g;s/\\x3A/:/g')" 2>/dev/null)" | |
else | |
folder="$(echo "$folder" | sed 's#^file://##;s/+/ /g;s/%\(..\)/\\x\1/g;')" | |
fi | |
if [ -n "$folder" ] && [ ! -e "$folder" ]; then | |
wsPath=$(dirname $wsJson) | |
echo "Removing workspace $(basename $wsPath) for deleted folder $folder of size $(du -sh $wsPath | cut -f1)" | |
rm -rf "$wsPath" | |
fi | |
fi | |
done | |
IFS="$OIFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment