index all rss twitter github linkedin email
Álvaro Ramírez

Á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.


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>>


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'."
   (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'


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'


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.


Optional error prompt

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


Configurable prompt

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


⚠️ Use with care ⚠️

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