Instead of the normal cd I've created my own function

function cd {
    builtin cd "$@" && ls -F

This works great for when I use commands like cd someDir/subDir but not when I change directories via zsh's auto_cd someDir/subDir.

Is there a way to customize what command gets called for auto_cd?


The typical way to run-some-command-on-the-changing-of-the-directory is via the chpwd hook function (or list of functions named in the appropriately named chpwd_functions array):

% function chpwd () { pwd }  
% cd ~/tmp
% pushd /etc
/etc ~/tmp
% chpwd_functions=( chpwd_do_ls )
% function chpwd_do_ls () { ls }
% cd /
Applications ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.