Not long after I got zsh-dwim up and running, I went mining in my old Zsh and Bash history files looking for potential transformation candidates. I thought I already implemented them all, but I was doing some spring cleaning and came across some of my notes. It turns out that I was wrong. There were still quite a few ideas in there that I haven’t implemented yet.
One of the more interesting ideas in there was related to the find command. Each time I write anything more complicated than the simplest find command line, I usually follow the same careful workflow:
- Run the command with no
-execoption to make sure the correct files are chosen - Add the
-execoption, butechothe commands first - Remove the
echo, and run it one last time
As you can see in the video, that’s precisely what this transformation does. If it isn’t already there, hitting control-u will add the -exec echo {} \; to the command and put the cursor in front of the curly bracket. If the -exec is already followed by an echo, then the echo is removed.
For good measure, one more press of control-u will convert the -exec to a -print0 | xargs -0.
There is a tiny new feature in zsh-dwim
I wanted to be able to automatically place the cursor directly before the curly bracket, but I didn’t have an existing mechanism to do that. The function that places the cursor after a successful transformation now sets the cursor position to the value of the _dwim_cursor variable, if it is defined.