[mikeserv@localhost ~]$ PS1=$PS1'$(
[ ${last_hist=\!} -ne \! ] && {
h=$(history 1)
[ -n "${h#"${h##* cd *}"}" ] &&
. ./.dircmd >&2 2>/dev/null
})${0##*["$0"$((last_hist=\!))]*}'
[mikeserv@localhost ~]$ cd .
[mikeserv@localhost ~]$
[mikeserv@localhost ~]$ echo
[mikeserv@localhost ~]$ cat <<\DIRCMD >.dircmd
echo this is my home directory
> DIRCMD
[mikeserv@localhost ~]$
[mikeserv@localhost ~]$ echo
[mikeserv@localhost ~]$ cd .
this is my home directory
[mikeserv@localhost ~]$
Something like that should work for a POSIX system - though I think only bash requires the \backslash before the !bang like that. bash also seems to update the history in a way that doesn't work with fc - which is portable - but does work with history. In other shells the history 1 bit should be exchangeable with fc -l -1 but bash does it a command behind, I guess. It was pretty frustrating.
Anyway, every time the prompt is drawn it defines the variable $last_hist as the history number for the last command. It does this in the match field on a parameter substitution that will always equal nothing so that doesn't show in the prompt.
The fc check just makes sure that the last history number actually incremented - as in, you didn't just hit enter or whatever. It also checks that the last command was a cd. If both are true it tries to . source a file in the current directory named .dircmd. If it exists it runs. If not, oh well.