Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZSH: automatically run ls after every cd

Tags:

zsh

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?

like image 897
drmanitoba Avatar asked Oct 18 '10 22:10

drmanitoba


1 Answers

EDIT: After looking at documentation (zshbuiltins, description of cd builtin or hook functions) I found a better way: it is using either chpwd function:

function chpwd() {     emulate -L zsh     ls -a } 

or using chpwd_functions array:

function list_all() {     emulate -L zsh     ls -a } chpwd_functions=(${chpwd_functions[@]} "list_all") 

Put the following into .zshrc:

function cd() {     emulate -LR zsh     builtin cd $@ &&     ls -a } 
like image 156
ZyX Avatar answered Oct 21 '22 13:10

ZyX