Skip to content

rtrppl/cleandesk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cleandesk.el

Cleandesk.el is a collection of functions to rapidly rename and process files in Dired.

The Idea

Pictures, PDFs and many other kinds of files frequently end up on my Desktop. In the past, I used Hazel and/or Devonthink to automatically rename and refile. Cleandesk offers an alternative (manual) approach for these tasks from within Emacs. It draws on Dired and fd.

To be sure, vanilla Dired probably can do most of this. But perhaps neither as convenient nor as swift.

Installation

Clone the repository:

git clone https://github.com/rtrppl/cleandesk

To run Cleandesk, you need to load the package by adding it to your .emacs or init.el:

(load "/path/to/cleandesk/cleandesk.el") ; You actually only need cleandesk.el

If your inbox folder is not the Desktop, you need to tell Cleandesk:

(setq cleandesk-inbox-folder "~/path/to/inbox")

In order to use Cleandesk you’ll want fd installed on your machine. The easiest way to do so might be homebrew, i.e. brew install fd. fd is much (!) faster than find but if you prefer find, you need to set this:

(setq cleandesk-search-tool "find") ; standard is fd

Attention: The first time you use cleandesk-jump-to-folder or cleandesk-move-files it will ask you to add a Cleandesk directory. A JSON list of these folders is stored in ~/.cleandesk-directory-list. For autocompletion, Cleandesk will only consider directories that are on this list (and their sub-directories).

The date-string, used by cleandesk-prepend-date and cleandesk-rename can be set via:

(setq date-string "%Y_%m_%d-%H%M%S-") ; this is the standard Cleandesk date-string

Finally, you may also want to set keybindings for the main functions (I have bound the Mac-Command Key to super/s):

(global-set-key (kbd "M-s-u") 'cleandesk-open-inbox)
(with-eval-after-load 'dired
  (define-key dired-mode-map (kbd "J") 'cleandesk-jump-to-folder)
  (define-key dired-mode-map (kbd "M") 'cleandesk-move-files)
  (define-key dired-mode-map (kbd "z") 'cleandesk-prepend-date)
  (define-key dired-mode-map (kbd "r") 'cleandesk-rename))

If you are on a Mac (see below) you may want to add a keybinding for cleandesk-search:

(global-set-key (kbd "M-s-u") 'cleandesk-open-inbox)
(with-eval-after-load 'dired
  (define-key dired-mode-map (kbd "J") 'cleandesk-jump-to-folder)
  (define-key dired-mode-map (kbd "M") 'cleandesk-move-files)
  (define-key dired-mode-map (kbd "z") 'cleandesk-prepend-date)
  (define-key dired-mode-map (kbd "S") 'cleandesk-search)
  (define-key dired-mode-map (kbd "r") 'cleandesk-rename))

Usage

To the Inbox

To quickly go to the Cleandesk inbox invoke M-x cleandesk-open-inbox (or the keybinding you have set). This will open a new Dired buffer showing the Cleandesk inbox.

Jump to a Directory

cleandesk-jump-to-folder allows you to jump to a Cleandesk directory or any of its sub-directories in Dired using a completion framework. While it was primarily intended for use in Dired, the function can be invoked from anywhere. If no Cleandesk directory is defined, the user is urged to add a directory as a Cleandesk directory (via cleandesk-add-folder).

This function and cleandesk-move-files are using fd, which can rapidly process 1000s of directories. To give you an idea: In my setup, Cleandesk operates with more than 5000 directories and there is no noticeable delay when preparing the list of directories for completion!

Prepend Date

cleandesk-prepend-date prepends the creation date of the file to the filename. If multiple files are marked in Dired, the date-string will be prepended to all of them.

Rename

cleandesk-rename prepends the creation date and also renames the file itself (but does not change the file extension). This also works across all marked files in Dired.

Move Files

cleandesk-move-files moves all marked files to a chosen Cleandesk directory or one of its sub-directories (selected via a completing framework such as Helm or Vertico).

Search

cleandesk-search uses the macOS Spotlight feature to search for a specific term in all files in the current directory. If called with C-u, search expands to all Cleandesk folders.

Housekeeping

cleandesk-add-folder adds folders to the list of Cleandesk folders, cleandesk-remove-folder will remove a folder from said list.

About

rapid renaming and sorting for dired

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages