Merge pull request #1783 from ZyX-I/check-bash-has-pipestatus

Check that bash has (no) $PIPESTATUS support before using it
This commit is contained in:
Nikolai Aleksandrovich Pavlov 2017-06-03 23:36:29 +03:00 committed by GitHub
commit 90032f8d0c
1 changed files with 13 additions and 1 deletions

View File

@ -31,10 +31,22 @@ _powerline_return() {
return $1
}
_POWERLINE_HAS_PIPESTATUS="$(
_powerline_return 0 | _powerline_return 43
test "${PIPESTATUS[*]}" = "0 43"
echo "$?"
)"
_powerline_has_pipestatus() {
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[*]}"