DEV Community

Katie McLaughlin
Katie McLaughlin

Posted on

Oh My Glob: alias expansion in zsh

I'm just getting on the zsh train, and while a lot of my personal customisation work has been around getting zsh to look like my old bashrc setup, I just learnt of one new feature that I never used in bashrc that is going to make my zsh experience much more friendly, especially to those looking on when I'm coding.


Alias Expansion is a concept where when you declare an alias

alias serveme="python -m http.server 1337"

Instead of just typing the alias, you hit a key sequence and it expands for you

By using the globalias ohmyzsh plugin, this automatically happens when you hit space.

$ serveme▊
$ python -m http.server 1337 ▊

Which is really nifty because there's no extra key presses required, and it helps you remember the full command (extra points!).

But not only that, it means that you can greatly improve your demos especially when you have super long commands to run all the time.

For example:

$ tail ~/.zshrc 
alias ka="kubectl apply -f"

$ ka▊
$ kubectl apply -f ▊

Shout-out to Mark for the tip!

Top comments (2)

Collapse
 
vonheikemen profile image
Heiker

The expansion should also work with special symbols like !! and !$.

If you forgot to add sudo before running a command you can type sudo !! + space to get right one.

Collapse
 
glasnt profile image
Katie McLaughlin

I knew of the sudo !! trick, but I never used it because I'd prefer to and edit to know exactly what I was running. This is a super useful extra trick! Thank you!