index rss mastodon twitter github linkedin email
Álvaro Ramírez
sponsor

Álvaro Ramírez

17 September 2022 $ rm Important.txt (uh oh!)

Setting Emacs up to use your system trash can potentially save your bacon if you mistakenly delete a file, say from dired.

Unsurprisingly, the trash safety net also extends to other Emacs areas. For example, discarding files from Magit (via magit-discard) becomes a recoverable operation. As an eshell user, the trash can also help you recover from rm blunders.

recovered_x1.6.webp

You can enable macOS system trash in Emacs by setting trash-directory along with defining system-move-file-to-trash:

(setq trash-directory "~/.Trash")

;; See `trash-directory' as it requires defining `system-move-file-to-trash'.
(defun system-move-file-to-trash (file)
  "Use \"trash\" to move FILE to the system trash."
  (cl-assert (executable-find "trash") nil "'trash' must be installed. Needs \"brew install trash\"")
  (call-process "trash" nil 0 nil "-F"  file))