From 10906c7fcf2251b8d63a89e8ee5ad9e2eabf803a Mon Sep 17 00:00:00 2001 From: Natercio Moniz Date: Thu, 23 Oct 2025 11:22:00 +0100 Subject: [PATCH] script to cleanup nvim env --- clean.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 clean.sh diff --git a/clean.sh b/clean.sh new file mode 100755 index 0000000..d095089 --- /dev/null +++ b/clean.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +set -euo pipefail + +SRC_DIRS=( + "$HOME/.local/share/nvim" + "$HOME/.local/state/nvim" + "$HOME/.cache/nvim" +) + +# Ask if user wants to backup +printf "Do you want to backup before cleaning? [Y/n]: " +read -r BACKUP_CHOICE +case ${BACKUP_CHOICE:-} in + [nN]|[nN][oO]) + BACKUP=false + ;; + *) + BACKUP=true + TAG=.bak-$(date +%Y-%m-%d_%H-%M-%S) + ;; +esac + +# Show plan and confirm +printf "\n" +if [ "$BACKUP" = true ]; then + printf "This will back up and clean your Neovim directories.\n" + printf "Backup suffix to be appended: %s\n\n" "$TAG" + printf "Plan:\n" + for SRC in "${SRC_DIRS[@]}"; do + if [ -e "$SRC" ]; then + DEST="${SRC}${TAG}" + printf " %s ➡️ %s\n" "$SRC" "$DEST" + fi + done +else + printf "This will remove your Neovim directories WITHOUT backup.\n\n" + printf "Plan:\n" + for SRC in "${SRC_DIRS[@]}"; do + if [ -e "$SRC" ]; then + printf " %s ❌\n" "$SRC" + fi + done +fi + +printf "\n" +read -r -p "Are you sure you want to proceed? [y/N]: " CONFIRM +case ${CONFIRM:-} in + [yY]|[yY][eE][sS]) ;; + *) printf "Aborted!\n"; exit 0;; +esac + +# Perform action based on backup choice +for SRC in "${SRC_DIRS[@]}"; do + if [ -e "$SRC" ]; then + if [ "$BACKUP" = true ]; then + DEST="${SRC}${TAG}" + mv "$SRC" "$DEST" + else + rm -rf "$SRC" + fi + fi +done + +printf "Done!"