#!/bin/sh -e

set -ux

# blue
info() { printf "\033[0;34m%s\e[0m\n" "$*" >&2; }
# green
success() { printf "\033[0;32m%s\e[0m\n" "$*" >&2; }

if command -v flatpak >/dev/null 2>&1; then
  info "[🚀 ] cleaning flatpak..."
  flatpak uninstall --unused --noninteractive --assumeyes
  if [ -d ~/.local/share/flatpak/system-cache ]; then
    command rm -rf ~/.local/share/flatpak/system-cache/*
  fi
fi

if command -v cargo-cache >/dev/null 2>&1; then
  info "[📦 ] cleaning cargo..."
  cargo-cache --autoclean
fi

if command -v gem >/dev/null 2>&1; then
  info "[💎 ] cleaning gem..."
  gem cleanup 2>/dev/null
fi

if command -v go >/dev/null 2>&1; then
  info "[🦍 ] cleaning go..."
  go clean -cache
  go clean
fi

# if command -v python >/dev/null 2>&1; then
#   info "[🐍 ] cleaning python..."
#   find "${@:-.}" -type f -name "*.py[co]" -delete
#   find "${@:-.}" -type d -name "__pycache__" -delete
#   find "${@:-.}" -depth -type d -name ".mypy_cache" -exec rm -r "{}" +
#   find "${@:-.}" -depth -type d -name ".pytest_cache" -exec rm -r "{}" +
# fi

if command -v uv >/dev/null 2>&1; then
  info "cleaning uv..."
  uv cache prune
fi

if command -v vim >/dev/null 2>&1; then
  info "[📓 ] cleaning vim..."
  find "${HOME}/.local/state/vim" -mindepth 1 -maxdepth 3 -mtime +10 -type f -delete
fi

{
  set +ux
} 2>/dev/null
