From a69bb88d7ec5b8cef5915d7f6cf631576e3dee37 Mon Sep 17 00:00:00 2001 From: pagedMov Date: Thu, 10 Oct 2024 21:34:30 -0400 Subject: [PATCH] Gen 310: added garbage-collect shell function to zshell.nix --- glasshouse-desktop/home/zsh/zshell.nix | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/glasshouse-desktop/home/zsh/zshell.nix b/glasshouse-desktop/home/zsh/zshell.nix index 79fafcb..a174e4a 100644 --- a/glasshouse-desktop/home/zsh/zshell.nix +++ b/glasshouse-desktop/home/zsh/zshell.nix @@ -40,9 +40,11 @@ mv = "mv -v"; cp = "cp -vr"; gt = "gtrash"; + gtp = "gtrash put"; grub-update = "sudo grub-mkconfig -o /boot/grub/grub.cfg"; sr = "source ~/.zshrc"; ".." = "cd .."; + rm = "echo 'use \"gtp\" instead'"; psg = "ps aux | grep -v grep | grep -i -e VSZ -e" ; mkdir = "mkdir -p"; pk = "pkill -9 -f"; @@ -66,6 +68,26 @@ ls() { s_check && runbg aplay ~/sound/sys/ls.wav } +garbage-collect() { + echo "This will delete all unused paths in the nix store and delete any files in the gtrash folder." + echo "\033[1;4;38;2;230;69;83mThis process is irreversible.\033[0m Are you sure? " + select yn in "Yes" "No"; do + case $yn in + Yes ) echo "Sweeping system...";break;; + No ) echo "Canceling garbage collection."; return;; + esac + done + output=$(nix-collect-garbage | tee /dev/tty) + + nix_freed=$(echo "$output" | grep -oP '\d+(\.\d+)? MiB freed' | cut -d' ' -f1) + rm_freed=$(du ~/.local/share/Trash/files/* ~/steamlib/.Trash-1000/files/* 2> /dev/null | awk '{sum += $1} END {print sum}') + rm_freed=$(echo "scale=2; $rm_freed / 1000" | bc) + /run/current-system/sw/bin/rm -rfv ~/.local/share/Trash/files/* + /run/current-system/sw/bin/rm -rfv ~/steamlib/.Trash-1000/files/* + total_freed=$(echo "$nix_freed + $rm_freed" | bc) + echo "System cleaning complete, freed $total_freed MiB in total" +} + cd() { export SOUNDS_ENABLED=0 eza -1 --group-directories-first --icons "$@" @@ -162,10 +184,10 @@ nsp() { nix-shell -p "$@" --run zsh } { eval "$(starship init zsh)" } + unalias ls clear splash s_check && (aplay ~/sound/sys/sh-source.wav > /dev/null 2>&1 &) - unalias ls ''; };