Trying to find a way to execute a function in BASH after changing to a directory.
eg,
# cd code/project/blah "Your latest modified files are main.cc blah.hpp blah.cc" (~/code/project/blah) # _
With the above, I hope that I will have the opportunity to wrap other functions around the BASH command.
I wanted to find something by the lines of the zsh hook functions http://zsh.sourceforge.net/Doc/Release/Functions.html#SEC45
Don't forget about pushd and popd if you never use them. I would do this:
pushd
popd
PS1='(\w) \$ ' chdir() { local action="$1"; shift case "$action" in # popd needs special care not to pass empty string instead of no args popd) [[ $# -eq 0 ]] && builtin popd || builtin popd "$*" ;; cd|pushd) builtin $action "$*" ;; *) return ;; esac # now do stuff in the new pwd echo Your last 3 modified files: ls -t | head -n 3 } alias cd='chdir cd' alias pushd='chdir pushd' alias popd='chdir popd'
You can make an alias for cd that performs standard cd , and then a specific function that you defined.
cd
Use PROMPT_COMMAND . You should take a look at git -sh, which includes many git fancy tricks, and should also be easy to learn.
PROMPT_COMMAND
alias cd='echo DO SOME WORK; cd $*'