0

I have the following in my .zshrc

alias la="ls -als"

And it's being overwritten

▶︎ which la
la: aliased to ls -lAh

Why is this happening / where might it be coming from?

loeschg
  • 29,961
  • 26
  • 97
  • 150

1 Answers1

1

Helped largely by https://stackoverflow.com/a/26742455/413254, it turns out that oh-my-zsh has some built in directory aliases in ~/.oh-my-zsh/lib/directories.zsh one of which overwrote my custom one!

▶︎ cat directories.zsh
# Changing/making/removing directory
...
# List directory contents
alias lsa='ls -lah'
alias l='ls -lah'
alias ll='ls -lh'
alias la='ls -lAh'

You could resolve this in a few ways:

  • Change my la alias to something else
  • Modify the above .oh-my-zsh file
  • Make sure that I'm defining my alias AFTER source $ZSH/oh-my-zsh.sh in my .zshrc. That source $ZSH/oh-my-zsh.sh sources basically everything in .oh-my-zsh/lib

I went with the last option.

loeschg
  • 29,961
  • 26
  • 97
  • 150
  • Right; assume that `oh-my-zsh.sh` can or will override anything you do yourself, and only do things before sourcing that file that are intended to *affect* that file. – chepner Apr 28 '22 at 15:25
  • (Or option 4: don't use `oh-my-zsh.sh` directly, instead cherry-picking the bits you find interesting and putting them in your configuration files directly.) – chepner Apr 28 '22 at 15:26