From a9773df25b6ee0e721b6b5e0e9f9872ffa86d796 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Wed, 29 Oct 2025 13:08:54 -0500 Subject: feat(dirvish): add file duplication with 'd' key, move deadgrep to 'D' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a convenient file duplication function to dirvish and reorganizes keybindings to avoid conflicts. ## Changes **1. New function: cj/dirvish-duplicate-file (dirvish-config.el:150)** Duplicates the file at point with "-copy" suffix before the extension: - report.pdf → report-copy.pdf - script.el → script-copy.el - README → README-copy Features: - Prevents duplicating directories (files only) - Checks if target exists and prompts to overwrite - Refreshes buffer automatically after copying - Shows clear message with old and new names **2. Keybinding changes** dirvish-config.el: - Bound 'd' to cj/dirvish-duplicate-file (was dired-flag-file-deletion) - Updated Commentary section to document new binding prog-general.el: - Moved cj/deadgrep-here from 'd' to 'D' (capital D) - More mnemonic: D for Deadgrep - Avoids conflict with new duplicate function ## Rationale The 'd' key is prime real estate in file managers, and duplicating files is a very common operation. The standard dired-flag-file-deletion is still available via 'x' or the mark-and-delete workflow. Deadgrep on 'D' is more discoverable (capital D for Deadgrep) and less likely to be pressed accidentally. ## Usage In dirvish, navigate to a file and press: - 'd' - Duplicate file with "-copy" suffix - 'D' - Search with deadgrep in current directory 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- modules/dirvish-config.el | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'modules/dirvish-config.el') diff --git a/modules/dirvish-config.el b/modules/dirvish-config.el index e35cc528..6c92db09 100644 --- a/modules/dirvish-config.el +++ b/modules/dirvish-config.el @@ -8,6 +8,7 @@ ;; ediff, playlist creation, path copying, and external file manager integration. ;; ;; Key Bindings: +;; - d: Duplicate file at point (adds "-copy" before extension) ;; - g: Quick access menu (jump to predefined directories) ;; - f: Open system file manager in current directory ;; - o/O: Open file with xdg-open/custom command @@ -145,6 +146,36 @@ Filters for audio files, prompts for the playlist name, and saves the resulting (dired-mark 1)) (forward-line 1)))) +;;; ------------------------ Dirvish Duplicate File Copy ------------------------ + +(defun cj/dirvish-duplicate-file () + "Duplicate the file at point with '-copy' suffix before the extension. +Examples: + report.pdf → report-copy.pdf + script.el → script-copy.el + README → README-copy" + (interactive) + (let* ((file (dired-get-filename nil t)) + (dir (file-name-directory file)) + (base (file-name-base file)) + (ext (file-name-extension file t)) ; includes the dot + (new-name (concat base "-copy" ext)) + (new-path (expand-file-name new-name dir))) + (unless file + (user-error "No file at point")) + (when (file-directory-p file) + (user-error "Cannot duplicate directories, only files")) + + ;; Check if target already exists + (when (file-exists-p new-path) + (unless (y-or-n-p (format "File '%s' already exists. Overwrite? " new-name)) + (user-error "Cancelled"))) + + ;; Copy the file + (copy-file file new-path t) + (revert-buffer) + (message "Duplicated: %s → %s" (file-name-nondirectory file) new-name))) + ;;; ----------------------- Dirvish Open File Manager Here ---------------------- (defun cj/dirvish-open-file-manager-here () @@ -286,7 +317,7 @@ regardless of what file or subdirectory the point is on." ("M-p" . dirvish-peek-toggle) ("M-s" . dirvish-setup-menu) ("TAB" . dirvish-subtree-toggle) - ("d" . dired-flag-file-deletion) + ("d" . cj/dirvish-duplicate-file) ("f" . cj/dirvish-open-file-manager-here) ("g" . dirvish-quick-access) ("o" . cj/xdg-open) -- cgit v1.2.3