Simplify

A few improvements:
- simplified the core logic (`newpwd`)
- replaced the `sed` used by `-si` with `perl`, to make it work in BSD too
- renamed `OLDPWD` to `oldpwd`, to avoid messing with the *real* `OLDPWD` automatically set by the shell when you change directories