Created
August 26, 2018 14:06
-
-
Save kodo-pp/b2bd42b45237ae2fbbd4c045a66db9f4 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
echo "Directory cleanup tool. For every file/dir in the current working directory it will ask you" | |
echo "if you want to remove it or not" | |
echo | |
echo "Files and directories won't be actually deleted until you delete the temporary" | |
echo "directory ~/.REMOVE" | |
echo | |
echo "This may be helpful if you accidently 'remove' something useful" | |
mkdir -p "$HOME/.REMOVE" | |
for i in *; do | |
if [[ "$i" == ".REMOVE" ]]; then | |
continue | |
fi | |
echo | |
if [[ -L "$i" ]]; then | |
echo -e "Symlink: \e[36m$i -> $(readlink $i)" | |
elif [[ -d "$i" ]]; then | |
echo -e "Directory: \e[38;5;33m$i" | |
else | |
filesize="$(du -h "$i" 2>/dev/null | awk '{print $1}')" | |
echo -ne "File: \e[35m$i\e[0m " | |
if [[ -z "$filesize" ]]; then | |
echo "(unknown size)" | |
else | |
echo "(size: $filesize)" | |
fi | |
fi | |
echo -ne '\e[0m' | |
select ans in remove keep shell; do | |
case $ans in | |
remove) | |
if [[ -d "$i" ]]; then | |
echo -ne "\e[33mWarning: this is directory. Continue? [y/N] \e[0;1m" | |
read ans | |
if [[ $ans != y ]]; then | |
echo -e "\e[0;32mKeeping $i\e[0m" | |
break | |
else | |
echo -e "\e[0;31mRemoving $i\e[0m" | |
fi | |
else | |
echo -e "\e[31mRemoving $i\e[0m" | |
fi | |
if ! mv -i "$i" "$HOME/.REMOVE/"; then | |
echo -n "Unable to move '$i' to ~/.REMOVE, remove it permanently? [y/N] " | |
read ans | |
if [[ $ans != y ]]; then | |
echo -e "\e[0;32mKeeping $i\e[0m" | |
else | |
echo -e "\e[1;31mRemoving $i permanently\e[0m" | |
rm -r "$i" | |
fi | |
fi | |
;; | |
keep) | |
echo -e "\e[32mKeeping $i\e[0m" | |
;; | |
shell) | |
echo -e "\e[34mStarting shell…\e[0m" | |
bash | |
continue | |
;; | |
*) | |
echo -e "\e[1;7;31mwtf?\e[0m" | |
continue | |
;; | |
esac | |
break | |
done | |
done | |
echo | |
echo "All files and directories you marked to remove now were moved into ~/.REMOVE" | |
echo "To permanently delete them, remove this directory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment