Improve shell detection.

* This code change copied over from rbenv-init