zsh: The Git Module
Zsh tab completion is great for
git. For instance, suppose you
git commit -- (with two dash characters at the end), and at
that point hit the tab key. You will see the available options for the
$ git commit --❚
--all -- stage all modified and deleted paths
--allow-empty -- allow recording an empty commit
--allow-empty-message -- allow recording a commit with an empty message
--amend -- amend the tip of the current branch
--author -- override the author name used in the commit
. . .
One thing I just learned about the Zshell tab completion is that it
doesn't just work from the end. In one of my "journal directory", I
entry_002.org, etc.††Yeah, I'm not sure what I'll do when I reach 1,000 entries. I guess I just don't think I'll be keeping it up that long
If I want to edit
entry_157.org, I can just type
157 and hit the
tab key. Typing just
15 shows me this list:
$ e 15❚
entry_015.org entry_150.org entry_152.org entry_154.org
entry_156.org entry_158.org entry_115.org entry_151.org
entry_153.org entry_155.org entry_157.org entry_159.org
But the tab completion feature for
git does not come from the
module from Oh My Zsh. That module just has around a billion
aliases for git commands, for instance:
alias gst='git status'
alias gl='git pull'
alias gup='git pull --rebase'
. . .
These aliases seem like a pretty good idea… except for remembering
to use them… and hopefully they won't conflict with any aliases you
currently use. As you may have noticed, my
.zshrc file already
g alias, but it uses Huy Nguyen's bashmarks project.
However, if you paid attention to the git commands you used often, and
created aliases yourself, you have a higher chance to use them. What
if we had the computer do the paying attention?
It already does, in your
~/.zsh_history file, so a quick analysis
should give you ideas for what you should alias first:
grep ';git ' ~/.zsh_history | \
cut -d' ' -f3- | cut -d'-' -f1 | sort | uniq -c
grep command grabs just the
git calls, and the first
removes the actual
git from the beginning of the line. The second
cut removes any options (but not file names or URLs‡‡That is left as an exercise to the reader. ).
uniq is just a way to help narrow the focus. The
uniq will tell you the number of occurences… if you type
git status 80 times (like I did this last week), an alias may be in
Since I've been actually busy programming, I'm just going to leave you
with this simple idea this week.
Tell others about this article: