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

Álvaro Ramírez

28 July 2022 dwim-shell-command improvements

Added a few improvements to dwim-shell-command.

Dired region

In DWIM style, if you happen to have a dired region selected, use region files instead. There's no need to explicitly mark them.

backup_x2.webp

Clipboard (kill-ring) replacement

Use <<cb>> to substitute with clipboard content. This is handy for cloning git repos, using a URL copied from your browser.

git clone <<cb>>

clone.webp

This illustrates <<cb>> usage, but you may want to use dwim-shell-commands-git-clone-clipboard-url from dwim-shell-commands.el instead. It does the same thing internally, but makes the command more accessible.

(defun dwim-shell-commands-git-clone-clipboard-url ()
  "Clone git URL in clipboard to `default-directory'."
  (interactive)
  (dwim-shell-command-on-marked-files
   (format "Clone %s" (file-name-base (current-kill 0)))
   "git clone <<cb>>"
   :utils "git"))

Counter replacement

Use <<n>> to substitute with a counter. You can also use <<3n>> to start the counter at 3.

Handy if you'd like to consistently rename or copy files.

mv '<<f>>' 'image(<<n>>).png'

numberedsorted_x2.2.webp

Can also use an alphabetic counter with <<an>>. Like the numeric version, can use any letter to start the counter with.

mv '<<f>>' 'image(<<an>>).png'

alphacount_x2.2.webp

Prefix counter

Use a prefix command argument on dwim-shell-commands to repeat the command a number of times. Combined with a counter, you can make multiple copies of a single file.

repeat.webp

Optional error prompt

Set dwim-shell-command-prompt-on-error to nil to skip error prompts. Focus process buffers automatically instead.

couldnt.png

Configurable prompt

By default, dwim-shell-command shows all supported placeholders. You can change that prompt to something shorter using dwim-shell-command-prompt.

prompt.jpg

⚠️ Use with care ⚠️

The changes are pretty fresh. Please use with caution (specially the counter support).