tag:blogger.com,1999:blog-3992530807750384868.post4687316892993493480..comments2022-03-28T08:42:20.497+03:00Comments on emacs-fu: using the systems 'trash' when deleting filesUnknownnoreply@blogger.comBlogger8125tag:blogger.com,1999:blog-3992530807750384868.post-73884696498221556552009-07-29T13:01:19.999+03:002009-07-29T13:01:19.999+03:00Please note use of the freedesktop.org trash can w...Please note use of the freedesktop.org trash can was added to emacs 23.2 (resolved bug #973). It was too late to make feature freeze for 23.1, but is in fact the default in CVS HEAD.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-78728597674293600702009-07-29T04:32:52.253+03:002009-07-29T04:32:52.253+03:00I've updated my solution. See EmacsWiki: http:...I've updated my solution. See EmacsWiki: http://www.emacswiki.org/emacs/SystemTrashUnknownhttps://www.blogger.com/profile/02143067975903176677noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-48856277861172623682009-06-11T14:37:00.904+03:002009-06-11T14:37:00.904+03:00Hmm. Using this can cause some problems. Files out...Hmm. Using this can cause some problems. Files outside your home directory are untrashable. In particular, files in /tmp/emacs1000/. If you use emacsclient, emacs will be unable to trash the server socket on exit, and next time you start emacs, emaceclient will not work.<br /><br />To fix this, we need a trash-or-rm command:<br /><br />$ cat > ~/bin/trash-or-rm.sh<br />#!/bin/sh<br /><br />## This attempts to trash a file (or files), and then attempts to remove it if it still exists.<br /><br />trash "$@" >/dev/null 2>&1<br />rm -f "$@"<br />[Control-D]<br /><br />I hope this blog didn't munge any characters in that script, but I think you get the idea. Then, <br /><br />(defun system-move-file-to-trash (filename)<br /> (shell-command (concat "trash-or-rm.sh " (shell-quote-argument filename))))<br /><br />Feel free to embellish the script as necessary. For example, you could manually move things to the trash if they're not too big.Unknownhttps://www.blogger.com/profile/02143067975903176677noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-86820874964346310032009-06-08T18:06:16.935+03:002009-06-08T18:06:16.935+03:00Oh, and if you don't use gvfs (part of GNOME),...Oh, and if you don't use gvfs (part of GNOME), you can install the trash-cli package and replace "gvfs-trash" with just "trash".Unknownhttps://www.blogger.com/profile/02143067975903176677noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-47849077239259002932009-06-08T18:04:55.970+03:002009-06-08T18:04:55.970+03:00How convenient that emacs provides a function for ...How convenient that emacs provides a function for shell-quoting things. This works perfectly.<br /><br />(defun system-move-file-to-trash (filename)<br /> (shell-command (concat "gvfs-trash " (shell-quote-argument filename))))Unknownhttps://www.blogger.com/profile/02143067975903176677noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-25061489638955686832009-05-16T23:53:00.000+03:002009-05-16T23:53:00.000+03:00Nice one. I prefer Unix "rm is serious business" ...Nice one. I prefer Unix "rm is serious business" semantics, but I didn't know Emacs did this, and I know people who would find it useful.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-14232960178381985992009-05-15T23:06:00.000+03:002009-05-15T23:06:00.000+03:00@jfm3: that's clever!
[ some quoting for the file...@jfm3: that's clever!<br /><br />[ some quoting for the filename is needed though.. suppose you have a file called "foo; cd $HOME; rm -rf *" ]djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-88676179440226667082009-05-15T22:41:00.000+03:002009-05-15T22:41:00.000+03:00capture the metadata:
(setq delete-by-moving-to-t...capture the metadata:<br /><br />(setq delete-by-moving-to-trash t)<br />(defun system-move-file-to-trash (filename)<br /> (shell-command (concat "gvfs-trash " filename)))jfm3https://www.blogger.com/profile/09025952927142374933noreply@blogger.com