If you are using bash, I would recommend you create a function like this:
function custom_cd() { custom_command $1; cd $1; }
alias cd='custom_cd'
Here your user command can be any that will execute certain commands in accordance with the directory you entered.
An alias declared later ensures that entering 'cd' will call the function and the real cd command.
:
function custom_cd() {
if [ -z "$1" ];
then
target=~
else
target=$1
fi
target=${target%/}
parent=$(dirname `readlink -f $target`)
grand_parent=`dirname $parent`
script=$grand_parent/`basename $target`.sh
if [ -x $script ];
then
`$script`
fi
cd $1
}
:
, , .
.
script grandparent.
, , script , , cd.
, , !