Skip to content

Instantly share code, notes, and snippets.

@hinell
Last active October 10, 2021 08:16
Show Gist options
  • Save hinell/63356a87b1b82a5d986750cb0de71413 to your computer and use it in GitHub Desktop.
Save hinell/63356a87b1b82a5d986750cb0de71413 to your computer and use it in GitHub Desktop.
List & filter workspace cache folder; use for cleanup

VSCode Workspaces Storage Filter Script

Release date: Sat, October 09, 2021

The script is intended to taclke the issue of leaky workspaceStorage of Microsoft Visual Studio Code. See related issue on github: VS Code#134532

Usage

# list cache folders
$ code.workspaces.cache.filter

# list vscode project cache folders
$ code.workspaces.cache.filter vscode

# export them into a $arr variable
$ code.workspaces.cache.filter vscode  arr

Install

# For Zsh
$ cat ./code.workspaces.cache.filter >> ~/.zshrc
# For Bash
$ cat ./code.workspaces.cache.filter >> ~/.bashrc

Uninstall

Remove the code.workspaces.cache.filter function from the ~/.{ba,z}shrc

# Title : Visual Studio Code Workspaces Storage Filter Script
# Summary : List & filter workspace cache folder; use for cleanup
# Created-at : Saturday, October 09, 2021
# Last-Modified : Saturday, October 09, 2021
# Repository :
# Authors : Alex A. Davronov <al.neodim@gmail.com> (2021-)
# Version : 1.0.0
# Description : TODO: add description
# Usage :
# # list cache folder
# $ code.workspaces.cache.filter
#
# # list vscode project cache folders
# $ code.workspaces.cache.filter vscode
#
# # export them into an $arr variable
# $ code.workspaces.cache.filter vscode arr
# Install : Install this into ~/.bashrc or ~/.zshrc
# Visual Studio Code Workspaces Storage Filter Script
# Copyright (C) 2021- Alex A. Davronov <al.neodim@gmail.com>
#
# Redistribution and (re)use of this Source or Binary code produced from such
# regardless of the carrier with or without modification is permitted free of
# charge (unless explicitly stated otherwise herewith) provided that
# the following conditions are met:
#
# 1. Redistributions of the Source code must retain the above
# Copyright notice, this List of conditions, and the following
# Disclaimer.
#
# 2. Redistributions of the Binary code must reproduce the above
# Copyright notice, this List of conditions, and the following
# Disclaimer visible prominently and clearly to the user's eyes
# within documentation provided with such distribution or at the
# user request immediately.
#
# 3. Failure to meet the List of condition set hereby terminates
# unconditionally your rights and permissions granted by the above
# Copyright notice and makes you eligible for prosecution, lawsuit or any
# legal actions or proceedings under appropritate law of a country of your
# or licensor's residence or International law if applicable.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#---------------------------------------------------code.workspaces.cache.filter
# See https://github.com/microsoft/vscode/issues/134532
# @param name - the project name to use as a filter
# @param arrayName - an array name to store paths to
code.workspaces.cache.filter(){
local name="$1";
local arrayName="$2";
local workspacesStoragePath="$HOME/.config/Code/User/workspaceStorage";
local ll="ls -ha -l -c --color --group-directories-first";
if [[ "$name" ]];
then
local ___arr=($(grep -lF "$name" $workspacesStoragePath/*/*.json));
[[ "$arrayName" ]] && {
eval "$arrayName=("${___arr[@]}")";
return 0;
};
for f in "${___arr[@]}";
do
ll -d $(dirname $f);
done;
else
# List all project's *.json files
ll $workspacesStoragePath/*/*.json
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment