Learning about your zsh aliases
I went through Armin Briegel’s “Moving to zsh” yesterday. It was illuminating, particularly in regard to zsh vs Oh My Zsh features. Take a basic example: aliases.
I went through Armin Briegel’s series of zsh orientation articles “Moving to zsh” yesterday. These articles are for people, primarily macOS IT admins, moving from bash to zsh.
He takes the position that it’s best to learn zsh first without adding Oh My Zsh on top of it. It’s a similar mindset to how JavaScript developers are often urged to learn vanilla JavaScript before leaning on jQuery to get things done.
While I agree with this way of thinking, I was introduced to zsh and Oh My Zsh in the same breath years ago, so the difference has never really been clear to me: it’s just worked.
A read through Briegel’s articles has been illuminating, particularly in regard to which features are coming from zsh vs Oh My Zsh.
Take a basic example: aliases.
First, what are aliases?
I’ve tended to think of shell aliases as shortcuts for commands that are either easy to forget or tedious to type.
Briegel describes aliases in this way:
You declare an alias with the alias (built-in) command and it will work as a text replacement at the beginning of the command prompt:alias ll='ls -al'
I keep a number of aliases in my .zshrc
file. A few examples:
alias hs="http-server"
alias marked="open -a 'Marked 2'"
alias gh="~/Scripts/gh-url/gh-url.sh"
In order, they:
- Start the
http-server
node module that I have installed globally - Open a given file in Marked 2, my preferred Markdown renderer:
marked readme.md
- Run a little script I made to open a git repo's remote origin in the browser
These make it simple to repeat common maneuvers without having type the whole command or re-remember how to write it in the first place.
Some options for learning about your zsh aliases
I mentioned yesterday that ...
is aliased to cd ../..
, but if you hadn't seen it before, you might not be able to guess what that alias maps to, where it comes from (zsh vs Oh My Zsh vs .zshrc
), or what other aliases you have available.
How would you go about finding these things out?
1. Identifying a single alias
First, an option that Briegel shares in “Moving to zsh, part 4: Aliases and Functions”.
The which
command will show if a command stems from an alias substitution:
% which ll
ll: aliased to ls -lh
This is a nice reminder when you know the alias you want but can't quite remember what it's set to.
2. Listing all available aliases
This one was news to me but a welcome new tool for remembering (and grepping) which aliases I have available: the alias
command.
Just type it in and hit enter to see every alias you have avaialable. I'll spare you my whole list.
Or, if you're wondering which aliases are available for, say, various flavors of ls
, you can grep the output:
$ alias | grep ls
As you can see, even ls
is an alias for ls -G
, enabling the colorized output for this command.
But I didn't set that ls
alias myself. Where is it coming from?
I was going to write about that here, but I ran out of leger. I'll share next time.