The obvious way would be to either implement it as a shell function or to use a small wrapper function that calls out to script which returns the new desired directory and then cd's to that.
I've set up an alias to source my script (xd.sh) like:
alias xd=. xd.sh
Sourcing the script allows it to change the current directory.
Have you open sourced this anywhere? Sounds extremely useful!