tags:

views:

41

answers:

3

So I've got ZSH doing all this cool stuff now, but what would be REALLY awesome is if I could get it to run 'ls -a' implicitly after every time I call 'cd'. I figure this must go in the .zlogin file or the .aliases file, I'm just not sure what the best solution is. Thoughts? Reference material?

+1  A: 

Write a function that performs the cd as requested, then performs a ls -a. Make sure you don't make it terribly difficult to disable though.

Ignacio Vazquez-Abrams
+1  A: 

You can do this via a simple alias:

alias cd='cd $* && ls -a'

Put this in your .zshrc

Brian Agnew
Downvoted why ?
Brian Agnew
Not a clue. Maybe someone thinks that you can't use positional parameters in aliases in zsh.
Ignacio Vazquez-Abrams
-1: alias is not a function, so `ls -a` will get the arguments while `cd` will not. You should have used function.
ZyX
@Ignacio Vazquez-Abrams you think you can?
ZyX
My tests (against zsh 4.3.9) suggest otherwise and that this works fine and as requested by the original questioner.
Brian Agnew
I can't duplicate your success with 4.3.10 here.
Ignacio Vazquez-Abrams
@Brian Agnew zsh 4.3.10, running this command before cd results in changing directory to `$HOME` and running a `ls -a` with all other arguments. Can you point where such `alias+$*` behavior is mentioned in documentation?
ZyX
I don't. I'm simply working from what's working on my current install.
Brian Agnew
I cannot find anything directly related to that in changelog, they only added `posixaliases` option setting/unsetting which does not alter the behavior of this alias.
ZyX
+1  A: 
ZyX
This works really well, I forgot to mention I have auto_cd turned on so this only works when I explicitly call 'cd'. Is there a way to get this to behave this way any time I change directories?
drmanitoba
@drmanitoba see updated answer.
ZyX
Awesome! Thanks so much!
drmanitoba