Gen 310: added garbage-collect shell function to zshell.nix

This commit is contained in:
pagedMov
2024-10-10 21:34:30 -04:00
parent 03181924a9
commit a69bb88d7e

View File

@@ -40,9 +40,11 @@
mv = "mv -v"; mv = "mv -v";
cp = "cp -vr"; cp = "cp -vr";
gt = "gtrash"; gt = "gtrash";
gtp = "gtrash put";
grub-update = "sudo grub-mkconfig -o /boot/grub/grub.cfg"; grub-update = "sudo grub-mkconfig -o /boot/grub/grub.cfg";
sr = "source ~/.zshrc"; sr = "source ~/.zshrc";
".." = "cd .."; ".." = "cd ..";
rm = "echo 'use \"gtp\" instead'";
psg = "ps aux | grep -v grep | grep -i -e VSZ -e" ; psg = "ps aux | grep -v grep | grep -i -e VSZ -e" ;
mkdir = "mkdir -p"; mkdir = "mkdir -p";
pk = "pkill -9 -f"; pk = "pkill -9 -f";
@@ -66,6 +68,26 @@ ls() {
s_check && runbg aplay ~/sound/sys/ls.wav 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() { cd() {
export SOUNDS_ENABLED=0 export SOUNDS_ENABLED=0
eza -1 --group-directories-first --icons "$@" eza -1 --group-directories-first --icons "$@"
@@ -162,10 +184,10 @@ nsp() { nix-shell -p "$@" --run zsh }
{ {
eval "$(starship init zsh)" eval "$(starship init zsh)"
} }
unalias ls
clear clear
splash splash
s_check && (aplay ~/sound/sys/sh-source.wav > /dev/null 2>&1 &) s_check && (aplay ~/sound/sys/sh-source.wav > /dev/null 2>&1 &)
unalias ls
''; '';
}; };