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

Álvaro Ramírez

04 May 2019 Batch file renaming with counsel, find-dired, and wdired

The first time I saw wdired in action, it blew my mind. wdired makes dired (directory editor) buffers writeable, so you can edit them like any other Emacs buffer. You can subsequently use all your favorite file-editing tricks to rename files (amongst other things). You can see it in action at the end of Emacs Rocks episode 16.

When combining find-dired with wdired, one can easily find matching files and quickly batch rename them using something like multiple cursors or keyboard macros. I've been a fan of the find-dired -> dired-toggle-read-only -> mc/mark-all-like-this workflow for quite some time, but I always wished I could adjust find-dired queries a little quicker by getting immediate feedback.

Completion frontends like ivy and helm are perfect for getting this kind of immediate feedback. Peeking into ivy's counsel source, I borrowed some ideas to glue counsel-style narrowing on a find command, which I can easily translate to a writeable dired buffer for all that joyful-mutiple-cursor-editing experience.

counsel-find.gif

The code for ar/counsel-find is a little rough but can be found at here.