You are not logged in.
Hi,
I'm using Xfce4 as my desktop environment.
And if I use Thunar to remove files, it will put these files into the trash can.
Usually I use "command line interface", so I wonder if there is a "remove" command that uses Xfce4's trash service?
If no, is it possible to create one?
Best regards,
bsdson.tw
Last edited by bsdson.tw (2007-03-26 04:01:08)
Offline
Could you alias the normal rm command to move files to xfce4 trash instead of deleting? I don't know the right location though...
Duettaeánn aef cirrán Cáerme Gláeddyv. Yn á esseáth.
Offline
I can write you a perl script that will use the command "xfcerm" that will place the file in the /home/username/.trash folder.
Or wherever xfce places files.
Arch Linux since 2006
Python Web Developer + Sys Admin (Gentoo/BSD)
Offline
I can write you a perl script that will use the command "xfcerm" that will place the file in the /home/username/.trash folder.
Or wherever xfce places files.
It does so where the freedesktop.org standards specify it should do it:
~/.local/share/Trash/files/
xfcerm, or how you call it (please not like that) should should implement the trash spec (it should know how to handle multiple files with the same filename). so it is not trivial for a cli-app.
Last edited by psyBSD (2007-03-19 10:12:05)
Offline
I'm looking at the freedesktop.org trash specification right now; it doesn't look too difficult. I'll come up with a quickie Python implementation and post it today or tomorrow.
Offline
It's probably best not to call it "rm" though. Not to big a problem when someone else uses your system, but maybe trouble when you use rm elsewhere and expect it not to blast the file. Perhaps "trash" or something like "rb" for rubbish would be better. Or "to" for "throw out" would be easier to type.
Offline
Update: I've been working on that Python script, it's around half done. There have been a few (minor) speed bumps, and I've been busier than I expected, so I may not post it for another couple days.
Offline
Is this script going to be xfce dependent? Something like this sounds handy even for a system that is comand-line only.
Offline
Is this script going to be xfce dependent? Something like this sounds handy even for a system that is comand-line only.
No, it won't depend on anything outside of the Python standard library. The first version will probably only support trashing files, but it shouldn't be much more work to add list and un-trash commands.
Offline
Here is my original "rm" implementation with trash-can support, hope that helps:
#!/bin/sh
# rm replacement with un-rm ability
# created by Henry
# prepare trashCan
trashCan=/home/trashCan/`date +%y%m%d/%H%M%S`
mkdir -p $trashCan
#
echo "DEL_BASE=$PWD" >> $trashCan/.files.del
echo "DEL_FILES=($*)" >> $trashCan/.files.del
# do rm
for file; do
mv $file $trashCan
done
There are some things that need to be modified:
1. the path to the trash-can, I use a semi-unique path to avoid conflictions
2. the target filename, now need to be considered.
3. the info file format
...
BR,
bsdson.tw
Last edited by bsdson.tw (2007-03-22 02:41:45)
Offline
My Python implementation is pretty much finished (minus listing and un-trashing, I'll add that later). I've done some testing, but there are probably still bugs in situations I didn't test.
I'm fighting my ISP's web site (why do the biggest companies hire the worst web designers?) to upload it to my web space. I'll post a download link when I can.
EDIT: Okay, here's the PKGBUILD, and the unpackaged script.
If it throws an exception at you, that's a bug, so report it.
EDIT 2: I released version 0.1.1. The only change is a re-licensing to GPL (instead of public domain). I've also uploaded it to the AUR.
Last edited by skymt (2007-03-22 20:05:54)
Offline
Thank you very much, skymt.
I'll try it out!
Sorry for late replying.
Offline
http://directory.fsf.org/libtrash.html
libtrash might be fun, and it'll act underneath rm and other standard apps. May not be fd.o compatible, but im sure the trash directory is configurable at least.
James
Offline
I wrote a little script for this. Only problem is that it only accepts full paths. I'll fix that later though, pretty functional as it is. Warning though: I wont take any responsibility if anything goes wrong.
#!/bin/bash
x="$1"; y="$2"
if [ "$x" != "-r" ]; then trash="$x"; else trash="$y"; fi
if [ "$x" == "-r" ]; then echo "rm -r $trash" >> ~/.rmtrash.sh; fi
if [ "$x" != "-r" ] && [ "$x" != "-c" ] && [ "$x" != "-e" ] && [ "$x" != "" ]; then echo "rm $trash" >> ~/.rmtrash.sh; fi
if [ "$x" == "-c" ]; then echo "" > ~/.rmtrash.sh; fi
if [ "$x" == "-e" ]; then sh ~/.rmtrash.sh; echo "" > ~/.rmtrash.sh; fi
Works like this. Just run the script along with the path as an argument and it will put it in a temporary script that stores it for later removal. If you add -r before the path, it will remove the contents of a folder as well. If you add -c as an argument, it will clear the trash without removing the files (not tested, but should work). If you add -e as an argument it will remove all files in the trash.
I prefer this way of handling trash than the regular 'move files to a folder' way, because this way it doesn't require any work from the harddrives. And it's also more friendly if you can't store everything in the trash because of partition sizes.
As for automatic trash removal, just add it to a cron with -e.
P.S: I know it's a really ugly script.
Edit: Forgot to mention, it's user dependent.
Last edited by Aziere (2007-03-26 10:56:05)
Offline
Here is my simple bash implementation,
which only do some simple error check and no auto recovery...
Hope this helps.
#!/bin/bash
# http://www.ramendik.ru/docs/trashspec.html
# home_trash_can=$XDG_DATA_HOME/Trash
# $home_trash_can/info
# $home_trash_can/files
# create XXX.trashinfo first
# [Trash Info]
# Path=$org_location/$org_filename # absolute path name
# DeletionDate=YYYY-MM-DDThh:mm:ss
# requirement:
# realpath
# -------------------------------------------------------
# init
deletion_date=$(date +%Y-%m-%dT%H:%M:%S)
home_trash_can=$XDG_DATA_HOME/Trash
if [ ! -d "$home_trash_can/info" -o ! -r "$home_trash_can/info" -o ! -w "$home_trash_can/info" ]; then
# 錯誤處理
echo "Something wrong with directory $home_trash_can/info..."
exit 4
fi
if [ ! -d "$home_trash_can/files" -o ! -r "$home_trash_can/files" -o ! -w "$home_trash_can/files" ]; then
# 錯誤處理
echo "Something wrong with directory $home_trash_can/files..."
exit 6
fi
# parse arguments
# nop
#
for file in "$@"; do
#
abs_path_name=$(realpath -s $file)
org_location=$(dirname $abs_path_name)
org_filename=$(basename $abs_path_name)
if [ ! -e $file -o ! -x $org_location -o ! -w $org_location ]; then
echo "Something wrong with file $file"
echo "abs_path_name=$abs_path_name"
echo
exit 8
fi
#
ext=""
while [ -e "$home_trash_can/info/$org_filename$ext.trashinfo" ]; do
#sleep .$RANDOM
ext=$(($ext + 1))
done
info="$home_trash_can/info/$org_filename$ext.trashinfo"
touch $info
echo "[Trash Info]" > $info
echo "Path=$abs_path_name" >> $info
echo "DeletionDate=$deletion_date" >> $info
#
mv $file $home_trash_can/files/$org_filename$ext&
done
Offline