I want to use different aliases (or perhaps: the same alias differently) depending on the current working directory. For example, I might want to use l
as a shorthand for ls
with some extra options. I want to use two variants:
alias l="ls --sort=extension" # variant A
alias l="ls --quoting-style=literal" # variant B
Normally, I would like to use variant A. However, I want to use variant B when listing pictures – that is, when my working directory is ~/pictures
. (This is merely a minimal example. My actual use case is more complicated.)
I am aware that I could simply write a function l()
with a case differentiation on the output of $(pwd)
. However, I want a more robust solution which allows me to rename the specific directories without changing any alias (and that doesn’t clutter my .zshrc
).
But is it possible to overwrite or add aliases, e.g. by setting up a local .zshrc
within the relevant directory (like it is possible for vim and a local .vimrc
)?
Furthermore, is it (also) possible in bash or any other shell?