tri6791

trash.sh

Jun 14th, 2011
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function question {
  4. ICON=/home/tri/icons/question.png
  5. if [[ -z $DISPLAY ]] || tty|grep -q pts; then
  6.   dialog --title Question --yesno "$*" 0 0
  7. else
  8.   yad --window-icon $ICON --image $ICON --center --on-top --title Question --text "$*" --button Yes:0 --button No:1
  9. fi
  10. }
  11.  
  12. function checksize(){
  13. S=(`du -bs "$1"`)
  14. if [ $S -gt 1000000000 ]; then
  15.   question "$1 size is greater than 1GB.  Delete permanently? \nNo will move it to trash"
  16. else
  17.   return 1
  18. fi
  19. }
  20.  
  21. [ $# -eq 0 ] && exit
  22. TRASHCAN="$HOME/.local/trash"
  23. mkdir -p $TRASHCAN
  24. case $1 in
  25.   *empty*)
  26.     rm -rf $TRASHCAN/* ;;
  27.   *restore*)
  28.     shift
  29.     for i; do
  30.       if [ ${i:0:1} = "_" ]; then
  31.         F=${i##*/}
  32.         F=${F//_/\/}
  33.         if [ -e "$F" ]; then
  34.           question "$F existed.  Do you want to overwrite?"
  35.           [ $? -eq 0 ] && mv -f "$i" "$F"
  36.         else
  37.           mv "$i" "$F"
  38.         fi
  39.       fi
  40.     done ;;
  41.   *)
  42.     for i; do
  43.       checksize "$i"
  44.       if [ $? -eq 1 ]; then
  45.         cd `dirname "$i"`
  46.         F=${PWD//\//_}_${i##*/}
  47.         mv -f "$i" $TRASHCAN/"$F"
  48.       else
  49.         rm -rf "$i"
  50.       fi
  51.     done ;;
  52. esac
Advertisement
Add Comment
Please, Sign In to add comment