Fix detecting parent shell on OpenBSD and Cygwin

It seems that "comm" header can't be relied on cross-platform, but that
"ucomm" is more portable. I have no idea whether it's the right value to
use here, but it seems to be doing the job.

Also strip trailing whitespace because OpenBSD 5.4 `ps` output is padded
with spaces for some reason.

Fixes #489
This commit is contained in:
Mislav Marohnić 2014-01-02 22:36:03 +01:00
parent eda535a942
commit 1a6bada94c

View file

@ -22,8 +22,9 @@ done
shell="$1" shell="$1"
if [ -z "$shell" ]; then if [ -z "$shell" ]; then
shell="$(ps c -p $(ps -p $$ -o 'ppid=' 2>/dev/null) -o 'comm=' 2>/dev/null || true)" shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}" shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")" shell="$(basename "${shell:-$SHELL}")"
fi fi