hi freaks!
for the
tcsh shell there exist a switch called '
rmstar' which prevents accidentally removing too much.
if you're using
bash and you also wish to receive a
warning when a star * is included in your deletion command, add the following to your .bashrc:
have fun with it.
Code:
alias rm="set -f; rmstar $@" #set -f to stop * from being expanded
rmstar () {
checkstar ${@} #check whether * is in argument
if [ ${PROCEED} != 'y' ]
then
inquire ${@} #if * found the user is asked whether he/she wants to continue
fi
if [ ${PROCEED} == 'y' ]
then set +f #enable expanding * again
\rm $@ #backslash by-passes alias
fi
}
inquire () {
echo -e "removing \e[1;32m ${RECUR} \e[0;31m ${@} \e[0m"
echo -n 'Are you sure? [y/N] '
read INQ
if [ ${#INQ} -ne 0 ]
then PROCEED=${INQ}
else #if nothing entered by user length of variable is zero
PROCEED='N'
fi
}
checkstar () {
PROCEED='y' #inquire whether to continue removing
RECUR='' #inquire whether -r is set as an option
if [[ $1 == -* ]]
then
if [ `expr index $1 'r'` -ne 0 ]
then RECUR='recursively'
fi
fi
for arg in ${@}
do
if [ `expr index ${arg} '*'` -ne 0 ]
then PROCEED='N'
fi
done
}