regexghost-dotfiles

My dotfiles and scripts
git clone git@git.regexghost.com/regexghost-dotfiles.git
Log | Files | Refs | README

rm-trash.sh (902B)


      1 #!/bin/sh
      2 
      3 # wrapper script around the rm, and trash-cli commands
      4 
      5 command="trash-put"
      6 dialog="rm: Trash"
      7 
      8 if [ "$1" = "-p" ]; then
      9 	shift
     10 	command="/usr/bin/rm"
     11 	dialog="rm: Delete (Permanently)"
     12 else
     13 	if ! which trash-put > /dev/null; then
     14 		echo "trash-cli not installed"
     15 		exit 1
     16 	fi
     17 fi
     18 
     19 for arg; do
     20 	filename="$arg"
     21 
     22 	# Refuse to delete / or ~
     23 	if [ "$filename" = "$HOME" ] || [ "$filename" = "/" ]; then
     24 		echo "Refusing to delete"
     25 		exit
     26 	fi
     27 
     28 	! [ -e "$filename" ] && echo "File/Directory doesn't exit" && continue
     29 	if [ -d "$filename" ]; then
     30 		if [ -z "$(ls -"$filename")" ]; then
     31 			read -p "${dialog} ${filename} (empty dir) (y/N) " confirm
     32 		else
     33 			read -p "${dialog} ${filename} (non-empty dir) (y/N) " confirm
     34 		fi
     35 		[ "$uservar" = "y" ] && "$command" -- "$filename"
     36 		continue
     37 	fi
     38 
     39 	read -p "${dialog} ${filename} (y/N) " confirm
     40 	[ "$confirm" = "y" ] && "$command" -- "$filename"
     41 done