Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- TRASH="$HOME/.Trash"
- HOP="\n\e[1;34mOPTIONS\e[m\n"
- HOP="$HOP""\t\e[1;34m-h\e[m\thelp\n\t\tmostra l'help ed esce\n\n"
- HOP="$HOP""\t\e[1;34m-v\e[m\tvisualizza\n\t\tmostra il contenuto del cestino\n"
- MHE="\n\t\t\e[1;37m-- DEL --\e[m\n"
- MHE="$MHE""\n\e[1;34mSYNOPSIS\e[m\n"
- MHE="$MHE""\tdel [ OPTIONS | PATHFILE1 PATHFILE2 PATHFILE 3 ... ]\n"
- MHE="$MHE""\n\e[1;34mDESCRIPTION\e[m\n"
- MHE="$MHE""\tUn cestino per terminale: 'del' non cancella i file definitivamente come 'rm',\n"
- MHE="$MHE""\tma li sposta nella directory Trashcan ove possono essere eventualmente recuperati.\n"
- MHE="$MHE""\tDirectory Trashcan (cestino) attuale: \e[1;32m$TRASH\e[m\n"
- MHE="$MHE""\tChiamato senza parametri 'del' svuota il cestino.\n"
- MHE="$MHE""$HOP"
- function _err() {
- if (($1)); then
- me="ERR$1: "
- me=$me$2
- echo -e "$me" >&2
- exit $1
- fi
- }
- function _help() {
- echo -ne $MHE
- }
- function _view() {
- echo -e "\t-- $TRASH --"
- echo "$(/bin/ls -Agh --color=always $TRASH)"
- }
- if [ ! -d "$TRASH" ]; then
- echo mkdir "$TRASH" &>/dev/null
- _err $? "Non riesco a creare il cestino"
- echo "Cestino creato"
- fi
- if ! (($#)); then
- cd "$TRASH"
- nf=$(/bin/ls -A | wc -l)
- if ((nf)); then
- /bin/ls -1 -A | rename 's/\.//g' &>/dev/null
- _err $? "Problemi nella preparazione dello svuotamento"
- rm -r * &>/dev/null
- _err $? "Non riesco a svuotare il cestino"
- echo "Cestino svuotato"
- else
- echo "Il cestino risulta vuoto"
- fi
- else
- case "$1" in
- "-h" ) _help ;;
- "-v" ) _view ;;
- * )
- mv $@ "$TRASH"
- _err $? "Problemi nel cestinamento"
- ;;
- esac
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment