Trivial stylistic update.
Check chdir() return status to avoid a compiler warning.
Fix suppression of the space char appended to a completed filename.

The previous implementation had a bug that was masked by another bug
in Readline 5.1 (which was fixed in Readline 6.0).