I went ahead and cleaned up zsh-dwim (Do What I Mean) quite a bit. If you haven't been following along, zsh-dwim attempts to predict your intended next command when you hit
control-u. I also recorded a short screen cast demonstrating some of what happens when you hit
Removing the Perl dependency
I decided that I may as well bite the bullet and move all the transformation logic to
zsh from the original Perl "helper" script. Early on, I was worried that
zsh code would be too ugly, but I have too many ideas that would be hard to implement with the code base split up like that.
All the transformation logic now uses
sed. I was hoping to use
zsh's built-in substitution abilities, but they were lacking some important features. The "scp to mv" transformation looked like it would have been really ugly without
Cleaning up the if/then spaghetti
When I was testing this idea I only had two transformations, so a pair of if/then statements didn't seem like a problem. Now that there are ten, it is starting to get ugly.
I ended up moving all the transformation definitions into a
zsh hash and I created a little helper function to add new definitions to that hash. When you call zsh-dwim, it loops over that hash testing for relevant transformations. This means we can now add transformations anywhere in our shell configuration.
Adding a transformation looks like this now:
_dwim_add_transform '^mkdir ' \ 'BUFFER=$(echo $BUFFER | sed -re "s/^mkdir /cd /")'
What's coming down the road?
There's still a lot of repetitive nonsense to eliminate. I need to factor out all those "BUFFER=$(echo $BUFFER | ... )" bits. They're repeated in every single transformation.
I'd also like to make use of more data in deciding which transformation to run. For instance, it might only make sense to call
ssh-keygen if the
ssh command fails.
The zsh-dwim repository is ready to be pulled into Prezto as a
git submodule. It can probably be used as a plugin with oh-my-zsh pretty easily, and the
init.zsh file can probably be
sourced right into plain old
zsh without, hopefully, any problem at all.
- Why I Finally Stuck With zsh
- autojump - The Lazy Way to Change Directories
- Improve Your oh-my-zsh Startup Time (Maybe)
- My Take on "The Go Command"
- Why I Started Using htop
- Automatically Expanding zsh Global Aliases As You Type
- Using and Customizing zsh-syntax-highlighting With oh-my-zsh
- Shell Environment Upgrade and Cleanup: Part 1 - Requirements and Planning
- Initial Release of zsh-dwim
- Cleanup of zsh-dwim
- Shell Environment Upgrade and Cleanup: Part 2 - Migrating from oh-my-zsh to Prezto
- Automatically Expanding zsh Global Aliases - Simplified
- Improving the Behavior of the cd Command in Git Repositories
- A Couple of Useful Snippets from My Shell Config
- A Small Update to `zsh-dwim`: rsync and dstat
- zsh-dwim: Most Recent Remote File Completion
- Upgrading from Autojump to Fasd
- zsh-dwim Now Works on Mac OS X and FreeBSD
- More Powerful Zsh Incremental History Search Using Zaw
- zsh-dwim: Transformations for the Find Command
- shstack: Persistent and Easy to Use Stacks Shared Between Shell Sessions
- zsh-dwim: Small Update For apt and dpkg