In “Learning about your zsh aliases”, I mentioned that you can get a full list of aliases available to you with the
alias command. For me, typing that in produces an enormous amount of output.
In fact, piping the
alias output to
alias | wc -l) shows that I have 217 aliases.
Woah. I didn’t make all of those. I have about 10 in my
For starters, I wonder where that
g=git alias and all of its friends came from…
Grepping your shell setup
It took a little digging around but I came across this StackExchange for Unix & Linux answer.
The tl;dr is this command:
% zsh -ixc : 2>&1 | grep ...
-i: Create an interactive shell.
-x: Print commands and their arguments as they are executed.
-c: Take the first argument as a command to execute.
I don't know all of the intricate details here but it's loading a shell and printing the trace, line-by-line, which you can then grep.
Let’s try it out.
Aliases from Oh My Zsh plugins
So if I know that I have a
g alias and I’m wondering where it’s coming from, I could do this:
% zsh -ixc : 2>&1 | grep "alias 'g=git"
Or more simply:
% zsh -ixc : 2>&1 | grep "alias 'g=" +/Users/arnwine/.oh-my-zsh/plugins/git/git.plugin.zsh:33> alias 'g=git'
The output is showing me that
g comes from
So all of the
git-related aliases are coming from Oh My Zsh’s
git plugin. Which makes sense, because I have enabled that plugin in
% cat .zshrc | grep git plugins=(git npm sudo z)
I could do a similar lookup for any of the aliases provided by the other plugins as well.
Aliases from Oh My Zsh lib and .zshrc
It might be worth noting that using this method of grepping your zsh setup for aliases will show more than just plugin-provided aliases.
Here’s one from
% zsh -ixc : 2>&1 | grep "alias 'ls=" +/Users/arnwine/.oh-my-zsh/lib/theme-and-appearance.zsh:24> alias 'ls=ls -G'
So now you know that if you use Oh My Zsh, your
ls command has been an alias all along.
And here’s an alias defined in my
% zsh -ixc : 2>&1 | grep "alias 'hs=" +/Users/arnwine/.zshrc:50> alias 'hs=http-server'
All good stuff to know if ever want to configure, override, or remove any of these aliases.
Beyond aliases: where are other config settings coming from?
In Armin Briegel’s “Moving to zsh, part 3: Shell Options”, he mentions the
AUTO_CD option, which I had always assumed was just a nicety included with zsh by default.
Instead, it turns out that’s actually a setting somewhere. But where? I looked, and it wasn’t in my
So I tried this:
% zsh -ixc : 2>&1 | grep -iE "setopt auto_?cd" +/Users/arnwine/.oh-my-zsh/lib/theme-and-appearance.zsh:42> setopt auto_cd
Wow, so it turns out this is also a setting that comes standard with Oh My Zsh.
I've learned that a lot of my zsh aliases and settings are coming from Oh My Zsh. That’s handy to know, as it lets me take more advantage of this great tool that’s been doing so much heavy lifting without my realizing it.