Giter Site home page Giter Site logo

trashed's Introduction

Trashed MELPA MELPA Stable

Viewing/editing system trash can in Emacs

Open, view, browse, restore or permanently delete trashed files or directories in trash can with Dired-like look and feel. In Emacs, You can trash files by deleting them with (setq delete-by-moving-to-trash t). This package provides a simple but convenient user interface to manage those trashed files. Supported trash cans are currently MS Windows Recycle Bin and freedesktop.org Trash Can.

Installation

This package is available on MELPA. You can install it with M-xpackage-installRETtrashedRET from within Emacs.

If you want to install manually, just put trashed.el somewhere in your load path and add below to ~/.emacs.d/init.el or ~/.emacs.

(require 'trashed)

Usage

Open Trashed

M-xtrashedRET, or use your favorite key binding like:

(global-set-key "\C-ct" 'trashed)

If (eq system-type 'windows-nt) such as mingw Emacs, it accesses Windows Recycle Bin under $Recycle.Bin folder in all drives. Otherwise such as Linux, it accesses freedesktop trash can under ~/.local/share/Trash or somewhere else XDG_DATA_HOME specifies. Windows XP or older is not supported.

View files

Open, view or browse file with f, v or W. Open or display file in another window with o or Ctrl-o.

Restore/delete files

Restore file with R or permanently delete file with D. If you want to do the action for multiple files at one time, mark them with m and execute the action with R or D. You can also flag one or multiple files for restoration or deletion with r or d and then execute the action with x at one time. If you want to simply empty trash can, just type M to mark all and type D. Unmark or unmark all are done with u or U.

Advanced marking

Regular expression based marking/flagging/unmarking can be used with %m, %r, %d or %u.

Date condition based marking/flagging/unmarking can be also used with $m, $r, $d, $u. Date condition must consist of <(before) or >(after), and N days ago. For example, <365 means mark all files deleted before the day 1 year ago, >30 means mark all files deleted after the day 1 month ago, >1 means mark all files deleted today.

Sorting

Sorting key or order can be changed by moving column with TAB or Shift-TAB to choose the key for sorting and typing S. Typing S again reverts the sorting order.

Mouse operation

You can use mouse for the operations above via right click menu or menu bar.

Help

See more information with C-hm.

Customization

trashed-use-header-line

Non-nil means Emacs window's header line is used to show the column names. Otherwise, text based header line is used.

trashed-sort-key

Default sort key. If nil, no additional sorting is performed. Otherwise, this should be a cons cell (COLUMN . FLIP). COLUMN is a string matching one of the column names. FLIP, if non-nil, means to invert the resulting sort.

trashed-size-format

Trash file size format displayed in the list. Options are below. Appropriate column width is set automatically.

  • plain -- Plain number
  • human-readable -- Human readable number formatted with file-size-human-readable
  • with-comma -- Number with comma every 3 digits

trashed-date-format

Deletion date format displayed in the list. Formatting is done with the function format-time-string. This actually allows you to configure wide variety of format and display it appropriately according to your system locale setting. See the function's description for details with C-hfformat-time-string. Appropriate column width is set automatically.

trashed-action-confirmer

  • Confirmer function to ask if user really wants to execute requested action. yes-or-no-p or y-or-n-p. If you really don't need any confirmation, you can set below at your discretion.
(defun always-yes-p (prompt) t)
(setq trashed-action-confirmer 'always-yes-p)

trashed-load-hook

Run after loading Trashed.

trashed-mode-hook

Run at the very end of trashed-mode.

trashed-before-readin-hook

Run before Trash Can buffer is read in (created or reverted).

trashed-after-readin-hook

Run after Trash Can buffer is read in (created or reverted).

Use in Emacs Lisp code

Trashed can be also used from within Emacs Lisp code for trash can maintenance. For example, below code in ~/.emacs.d/init.el or ~/.emacs deletes trashed files which were deleted 1 years ago or before every time Emacs is killed.

(defun always-yes-p (prompt) t)

(add-hook 'kill-emacs-hook
          #'(lambda ()
              (let ((trashed-action-confirmer 'always-yes-p))
                (trashed)
                (trashed-flag-delete-files-by-date "<365")
                (trashed-do-execute))))

TODO

  • Menu bar
  • Date based marking (mark files 1 month ago or older, etc)
  • Support MS Windows Recycle Bin
  • ...any request/suggestion is appreciated

trashed's People

Contributors

shingo256 avatar

Stargazers

Ravioli avatar Hoang Van Nhat avatar Nick Anderson avatar  avatar John Hamelink avatar SDO avatar  avatar KOBAYASHI Shigeru avatar Qingshui Zheng avatar  avatar Wing Hei Chan avatar Andy Shevchenko avatar  avatar Oleg Pykhalov avatar FCP avatar Yuan Fu avatar  avatar  avatar Masashi Miyaura avatar  avatar  avatar Fox Kiester avatar Akira Komamura avatar Clemens Radermacher avatar Adam Porter avatar

Watchers

 avatar  avatar

trashed's Issues

NonGNU Elpa?

There is this newfangled repository at NonGNU Elpa. It's like ELPA but you don't need to be a card-carrying FSF member.

Submitting this package to NonGNU ELPA would make it accessible to future Emacs users (since NonGNU will be part of Emacs28+) and improve visibility!

Suggestion

Hi,

Great work converting to use tabulated-list-mode!

Here's some code you might want to use that simplifies the implementation of trashed-read-files a bit. I think it makes it easier to understand.

(defun trashed-read-files ()
  (let* ((files (directory-files-and-attributes trashed-files-dir nil nil t))
         (entries (cl-loop for (name . attrs) in files
                           unless (or (string= name ".") (string= name ".."))
                           collect (trashed-file-info name attrs))))
    (setf tabulated-list-entries entries)))

(defun trashed-file-info (name attrs)
  "Return list of name and vector for `tabulated-list-entries' for file NAME with ATTRS."
  (-let* ((type (cl-typecase (file-attribute-type attrs)
                  (string "l")
                  (null "-")
                  (t "d")))
          (size (number-to-string (file-attribute-size attrs)))
          (info-file (expand-file-name (concat name ".trashinfo") trashed-info-dir))
          ((path deletion-ts) (trashed-trashinfo info-file))
          (path (-> path url-unhex-string
                    (decode-coding-string 'utf-8 t)
                    (propertize 'mouse-face 'highlight)))
          (deletion-ts (format-time-string "%Y-%m-%d %H:%M:%S" deletion-ts)))
    (list name (vector type size deletion-ts path))))

(defun trashed-trashinfo (trashinfo-file)
  "Return list of original file path and deletion timestamp for TRASHINFO-FILE."
  (when (file-readable-p trashinfo-file)
    (with-temp-buffer
      (insert-file-contents trashinfo-file)
      (let* ((path (when (re-search-forward (rx bol "Path"
                                                (0+ blank) "=" (0+ blank)
                                                (group (1+ nonl))) nil t)
                     (match-string 1)))
             (deletion-ts (progn
                            (goto-char (point-min))
                            (when (re-search-forward (rx bol "DeletionDate"
                                                         (0+ blank) "=" (0+ blank)
                                                         (group (1+ nonl))) nil t)
                              (parse-iso8601-time-string (match-string 1))))))
        (list path deletion-ts)))))

Also, in the header, it says Data & Time instead of Date & Time. You might want to use something more explicit like Deleted At.

BTW, you might find this interesting. :) https://github.com/alphapapa/rubbish.py

Errror when there is no directory for trashcan

Running trashed throws an error if I have never used the trashcan:

trashed-read-files: Opening directory: No such file or directory, /home/akirakomamura/.local/share/Trash/files

Apparently this is caused by evaluating the following expression in the function:

(directory-files-and-attributes trashed-files-dir nil nil t)

It can be prevented by putting the expression inside (ignore-errors ...).

Some valid info files are rejected

Hi,

I noticed that some valid info files are rejected. For example, this one is skipped, apparently because of the spaces around the =, even though it's a valid file:

[Trash Info]
Path = /home/me/src/emacs/melpa/sandbox
DeletionDate = 2019-09-09T19:45:50

I also added a fix for this in #1

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.