Created
January 6, 2022 02:41
-
-
Save scarf005/6e6c20771074f9dbfd4759b496770eaa to your computer and use it in GitHub Desktop.
because 5GB is never enough
This file contains hidden or 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/env python3 | |
from __future__ import annotations | |
from os import environ, system | |
from pathlib import Path | |
from typing import Dict, Generator, List | |
CacheDirs = Dict[Path, List[str]] | |
HOME = Path(environ["HOME"]) | |
apps = HOME / "Library" / "Application Support" | |
goinfre = HOME / "goinfre" / "caches" | |
names: CacheDirs = { | |
HOME / "Library": ["Caches"], | |
apps | |
/ "Code": [ | |
"Cache", | |
"CachedData", | |
"CachedExtensions", | |
"CachedExtensionVSIXs", | |
"Code Cache", | |
"User/workspaceStorage", | |
], | |
apps | |
/ "Slack": [ | |
"Cache", | |
"CachedData", | |
"Service Worker/CacheStorage", | |
"Service Worker/ScriptCache", | |
], | |
apps | |
/ "Google" | |
/ "Chrome" | |
/ "Profile 1": ["Service Worker/CacheStorage", "Extensions"], | |
HOME / ".brew" / "Library" / "Taps" / "homebrew": ["homebrew-core/.git"], | |
HOME / ".brew": [".git"], | |
HOME / ".vscode": ["extensions"], | |
} | |
def caches(names: CacheDirs) -> Generator[Path, None, None]: | |
for directory, caches in names.items(): | |
yield from (directory / cache for cache in caches) | |
def to_goinfre(path: Path) -> Path: | |
return goinfre / path.relative_to(HOME) | |
def main(): | |
for f in caches(names): | |
link, go = Path(f), to_goinfre(f) | |
if not any([link.is_dir(), link.is_file()]) or any( | |
[link.is_symlink(), go.is_file(), go.is_dir()] | |
): | |
continue | |
go.parent.mkdir(parents=True, exist_ok=True) | |
system(f'mv "{link}" "{go}"') | |
link.symlink_to(go) | |
print(f"{link} -> {go}") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment