Check that bash has (no) $PIPESTATUS support before using it

Ref #1782
This commit is contained in:
Foo 2017-06-02 21:12:05 +03:00
parent 3df98fc276
commit 3c49ed1e96

View File

@ -31,10 +31,26 @@ _powerline_return() {
return $1
}
_POWERLINE_HAS_PIPESTATUS=
_powerline_has_pipestatus() {
if test -z "$_POWERLINE_HAS_PIPESTATUS" ; then
_powerline_return 0 | _powerline_return 43
if test "${PIPESTATUS[*]}" = "0 43" ; then
_POWERLINE_HAS_PIPESTATUS=0
else
_POWERLINE_HAS_PIPESTATUS=1
fi
fi
return $_POWERLINE_HAS_PIPESTATUS
}
_powerline_status_wrapper() {
local last_exit_code=$? last_pipe_status=( "${PIPESTATUS[@]}" )
if test "$last_exit_code" != "${last_pipe_status[-1]}" ; then
if ! _powerline_has_pipestatus \
|| test "${#last_pipe_status[@]}" -eq "0" \
|| test "$last_exit_code" != "${last_pipe_status[-1]}" ; then
last_pipe_status=()
fi
"$@" $last_exit_code "${last_pipe_status[*]}"