Last active
December 23, 2022 16:44
-
-
Save rcmdnk/5439030 to your computer and use it in GitHub Desktop.
rm wrapper to protect HOME and / directory.
To use, put this gist in your .bashrc or .bash_profile.
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
#alias rm="rm -i" | |
#function rm={ rm $@ -i; } | |
function rm { | |
for f in "$@";do | |
if [[ "$f" =~ ^- ]];then | |
continue | |
fi | |
if [ "$f" = "$HOME" ] || [ "$f" = "$HOME/" ];then | |
echo -n 'Are you sure to remove your HOME? ' | |
read yes | |
if ! [[ "$yes" =~ ^[yY] ]];then | |
return 0 | |
fi | |
elif [ -d $f ];then | |
dn="$(cd "$(dirname $f)";pwd -P)" | |
if [ "$dn" = "$HOME" ] || [ "$dn" = "$HOME/" ];then | |
echo -n 'Are you sure to remove your HOME? ' | |
read yes | |
if ! [[ "$yes" =~ ^[yY] ]];then | |
return 0 | |
fi | |
fi | |
fi | |
done | |
command rm --preserve-root $@ | |
#command rm -i --preserve-root $@ | |
#command rm --preserve-root $@ -i | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment