Fact: Shell aliases save you time.
Fact: Saving time increases your productivity.
Fact: Everybody wants to be more productive.
Fact: Retraining muscle memory can be a pain in the ass.
I have been fighting that last fact for a while now. I have the single character
alias v
pointed to vim
. A whopping 67% decrease in characters I need to type
to run vim
. After 10+ years of typing in vim
, I found it very hard to break
the habit and transition over to the single character alias.
Then it hit me! Why not break vim
so that I couldn’t run it directly, thus
forcing me to use the alias! And that’s what I set out to do.
To start, I created a bin
directory in my dotfiles, added a new file named
vim
and made it executable:
mkdir ~/.dotfiles/bin
touch ~/.dotfiles/bin/vim
chmod +x ~/.dotfiles/bin/vim
I then opened up the vim
file and wrote the following:
#!/usr/bin/env bash
if [[ `ps -o stat= -p $PPID` == *"s"* ]] then
echo ""
echo -e "e`v`e[0m"
echo -e "ee[0m"
exit 1
else
/usr/local/bin/vim $@
fi
The conditional checks to see if the script is being invoked directly or not.
Without that I was running into issues with other scripts that would call vim
and updating my $EDITOR
didn’t seem to resolve anything.
After the script was in place, I made a few adjustments to some variables in my
.zshrc
file. First, I updated my v
alias to use the full path for my vim
executable instead of just vim
:
alias v="/usr/loca/bin/vim"
And updated my $PATH
to check the bin
I created in my dot files:
export PATH=~/.dotfiles/bin:/usr/local/bin:/usr/local/sbin:$PATH
With these changes made, I restarted my terminal and am now greeted by this
whenever I try to run vim
:
Extreme? Yeah it is, but it’s going to force me to adapt, which is a very good
thing. I’ve spent the last week using that and have absolutely no regrets. I’m
even planning to do the same thing with a handful of other aliases as well!
If you’re interested in seeing which commands you type often and where you would
benefit from some aliases, check out HuffShell, a gem for
suggesting new aliases based on your history.
Also, my dotfiles are available for perusing and poaching if you’re
interested.