You are not logged in.

#1 2009-01-07 10:14:27

fulloffur
Member
Registered: 2007-09-24
Posts: 20

A simple trash script for lxpanel

Basically, I'm using lxde, and pcmanfm doesn't do trash...
So this is a simple bash script for a trash in the lxpanel that you can drag your unwanted files into.

Limatiations/Assumptions:
1) Only for users with home folders in /home, i.e., will not work for root.
2) All external drives are mounted to /media
3) No restore function, have to manual search for files in trash folder
4) No tracking of deletion time
5) No warning if you umount drive with trash
6) Honestly, it's just to mv files to .trash.

What it does:
Moves files to $HOME/.Trash or /media/[something]/.Trash
Delete .Trash
Uses xmessage for gui
Options to delete home, media or all trash.

Copy the following to a text file named "movetotrash"

#!/bin/bash
export IFS=$'\r\n'

if [ "$#" -eq 0 ] ; then
        FILELIST=`ls -A1sh ~/.Trash`
        TRASHSIZE=`du -sh ~/.Trash`
        MESSAGE="

HOME TRASH:
$TRASHSIZE
  -----
$FILELIST
  -----

"
        for i in `mount |grep /media/ |awk '{print $3}'` ; do
                if [ -d $i/.Trash ] ; then
                        FILELIST=`ls -A1sh $i/.Trash`
                        TRASHSIZE=`du -sh $i/.Trash`
                        MESSAGE="

$MESSAGE
$i:
$TRASHSIZE
  -----
$FILELIST
  -----

"
                TRASHLIST="$TRASHLIST
$i/.Trash"
                fi
        done
        xmessage -default no -buttons no:1,home:0,media:3,all:2 -center "

$MESSAGE

Empty Trash?

"
        ACTION=$?
        if [ "$ACTION" -eq "0" ] ; then
                rm -rf $HOME/.Trash/*
                rm -rf $HOME/.Trash/.*
                xmessage -timeout 5 "Home Trash deleted"
                exit
        fi
        if [ "$ACTION" -eq "3" ] ; then
                for i in $TRASHLIST ; do
                        rm -rf $i
                done
                xmessage -timeout 5 "Media Trash deleted"
                exit
        fi
        if [ "$ACTION" -eq "2" ] ; then
                rm -rf $HOME/.Trash/*
                rm -rf $HOME/.Trash/.*
                for i in $TRASHLIST ; do
                        rm -rf $i
                done
                xmessage -timeout 5 "All Trash deleted"
                exit
        else
                exit
        fi
fi

for i in $@ ; do
        trashdir=`echo -n "$i" | awk -F "/" '{ print "/"$2"/"$3"/.Trash/" }'`
        if [ ! -d "$trashdir" ] ; then
                mkdir "$trashdir" || { xmessage -timeout 5 "Error Creating Trash Directory" && exit ; }
        fi
        mv "$i" "$trashdir"
done

then make the file executable and copy to /usr/bin

chmod +x movetotrash
cp movetotrash /usr/bin

then create a trash.desktop file in /usr/share/applications with the following

[Desktop Entry]
Encoding=UTF-8
Exec=movetotrash %F
Icon=user-trash
Type=Application
Terminal=false
Name=Trash
GenericName=Trash
StartupNotify=false
Categories=Application

then add it as an application in lxpanel.

Or if you use rox, can use it as a appdir...

Kind of new to bash script. Actually this is a learning thing for me. Sorry for the ugly code and stuff. And urm... if it doesn't work... don't hate me.

Offline

#2 2009-01-08 15:13:14

ogronom
Member
From: Toronto, Canada
Registered: 2008-05-06
Posts: 123

Re: A simple trash script for lxpanel

why didn;t you use traash_cli to get better suuport with standart trash?

Offline

#3 2009-01-09 02:52:00

fulloffur
Member
Registered: 2007-09-24
Posts: 20

Re: A simple trash script for lxpanel

I didn't know about trash_cli. But after your post, I tried to install the trash_cli, it doesn't work for me, lots of python errors.

I know there's something like libtrash also.

But the problem is that I don't like the trash behaviour. I use a few external usb harddrives. When I trash a file in the external harddrive, it will move the file to my home harddrive. This is especially annoying when I trash large files. Kde also have this behaviour.

Anyways, I just wrote this script to try to emulate the gnome trash behaviour. Which is to create different trash directory on different drives. I think windows does this too.

Not sure how trash_cli will handle trash of external drives. But thank you.

Offline

#4 2009-01-10 03:14:35

ogronom
Member
From: Toronto, Canada
Registered: 2008-05-06
Posts: 123

Re: A simple trash script for lxpanel

After switching to python2.6 PKGBUILD don't work. I post a bug, but nabtaiber didn't answer
Source of problem -- wrong destination directory for the library: "python" instead of "python26". Can be handled manually.

Strange... my gnome creates ".Trash-<username>" in the extrenal drives and uses them. Don't know about trash_cli and extrenal drives, but it works well with my gnome and xfce trashes.

Offline

#5 2009-01-11 04:21:12

fulloffur
Member
Registered: 2007-09-24
Posts: 20

Re: A simple trash script for lxpanel

Hmm... I tried to edit the pkgbuild to install to python26. Then there's error when installing the package. Something like 'site.py' already exists... To be honest, I know nothing about python...

In the end, I tried using the easy-install method, that the main site recommends. Still have errors....

I give up...

But thanks anyway.

Offline

Board footer

Powered by FluxBB