WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: trash  (Read 3934 times)

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
trash
« on: November 20, 2009, 10:42:52 AM »
Moves file/folder to trash directory with $1 (eg, "trash myfile").  Without $1 (eg, "trash"), prompts
for deleting.  Edit PATH (script will create/remove directory).  

For use with DFM, create icon. Set shellcommand to "aterm -e !0!".  Drag files to icon (move), or click for viewing/deleting.

Code: [Select]
#!/bin/ash


#### trash.sh script, jeters
###  deletes $1 files/folders; without $1, prompts to view/delete

## Edit PATH:
TRASH="/mnt/hda3/tmp/trash"

. /etc/init.d/tc-functions

[ -d /mnt/hda3/tmp/trash ] || sudo mkdir -p ${TRASH}

if [ $1 ]; then
  sudo mv "$@" ${TRASH}
else
  if [ "$(ls ${TRASH})" ]; then
     clear
     ls ${TRASH}
     echo "_____________"
     echo ${GREEN}"delete? (y)"${NORMAL}
     read RESPONSE
       case ${RESPONSE} in
         "y" )  sudo rm -R ${TRASH} ; echo ${RED}"deleted!" ${NORMAL}; sleep 1 ;;
         "*" )  break ;;
       esac
   else
     echo ${GREEN}"Empty" ${NORMAL}; sleep 1
   fi

fi

exit 0
      
     
      
« Last Edit: November 23, 2009, 11:28:33 AM by jpeters »

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: trash
« Reply #1 on: November 20, 2009, 10:55:57 AM »
screenshot with DFM

[removed due to policy]apps/trash.png

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: trash
« Reply #2 on: November 22, 2009, 01:39:36 AM »
Updated to more user friendly version.

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: trash
« Reply #3 on: November 22, 2009, 01:37:35 PM »
updated to include multiple arguments: eg, "trash file1 file2 mydir";  also "trash myfiles*"


Offline mikshaw

  • Sr. Member
  • ****
  • Posts: 368
Re: trash
« Reply #4 on: November 23, 2009, 06:01:48 AM »
Code: [Select]
  while [ $# -ge 1 ];do
     sudo mv ${1} ${TRASH}
     shift
   done
Could this be done in just one command rather than a loop?  The mv command supports mulitple files.
Code: [Select]
sudo mv "$@" ${TRASH}
The directory test is using a specific path rather than $TRASH

The delete confirmation could be improved.  If you just press enter when the "y" is visible, you get an error.  It is common to have a default selection displayed in uppercase -- Delete? (y|N) -- which allows the user to just press enter to accept the default.  The error can be avoided either by first testing for the existence of $RESPONSE before comparing it to "y", or by using case instead of if.

Personally I wouldn't delete the trash directory, only its contents...but I can see reasons for doing that.

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: trash
« Reply #5 on: November 23, 2009, 09:51:13 AM »
Code: [Select]
 while [ $# -ge 1 ];do
     sudo mv ${1} ${TRASH}
     shift
   done
Could this be done in just one command rather than a loop?  The mv command supports mulitple files.
Code: [Select]
sudo mv "$@" ${TRASH}
The directory test is using a specific path rather than $TRASH

The delete confirmation could be improved.  If you just press enter when the "y" is visible, you get an error.  It is common to have a default selection displayed in uppercase -- Delete? (y|N) -- which allows the user to just press enter to accept the default.  The error can be avoided either by first testing for the existence of $RESPONSE before comparing it to "y", or by using case instead of if.

Personally I wouldn't delete the trash directory, only its contents...but I can see reasons for doing that.

Thanks mikshaw. Always great to have your expertise.  I removed the loop and fixed the bug, as you suggested. The (y|N) looks like (yIN) on my computer, so others can add that if they want..although it's not needed.  I  kindof like deleting the whole directory, since it's easier to move around, etc., but that could be edited:  "y" )  sudo rm -R ${TRASH}/*  ....
« Last Edit: November 23, 2009, 01:30:51 PM by jpeters »