Improve shell detection.

* This code change copied over from rbenv-init
Merge pull request #62 from finn/master

Improve shell detection.