From 3c49ed1e96df6513528729feee6e61fd101dfef8 Mon Sep 17 00:00:00 2001 From: Foo Date: Fri, 2 Jun 2017 21:12:05 +0300 Subject: [PATCH 1/2] Check that bash has (no) $PIPESTATUS support before using it Ref #1782 --- powerline/bindings/bash/powerline.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index 4ec0d72c..618cb0d0 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -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[*]}" From d3e5d99a20305d5f71e3d383d1005d232d3efcc9 Mon Sep 17 00:00:00 2001 From: Foo Date: Fri, 2 Jun 2017 21:23:03 +0300 Subject: [PATCH 2/2] Do not spawn jobs With previous variant of code first call has spawned a job which was perfectly reproducibly visible in prompt at bash startup. In subsequent prompts job number segment disappeared because result was cached, but it still was not good. --- powerline/bindings/bash/powerline.sh | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/powerline/bindings/bash/powerline.sh b/powerline/bindings/bash/powerline.sh index 618cb0d0..db831fd5 100644 --- a/powerline/bindings/bash/powerline.sh +++ b/powerline/bindings/bash/powerline.sh @@ -31,17 +31,13 @@ _powerline_return() { return $1 } -_POWERLINE_HAS_PIPESTATUS= +_POWERLINE_HAS_PIPESTATUS="$( + _powerline_return 0 | _powerline_return 43 + test "${PIPESTATUS[*]}" = "0 43" + echo "$?" +)" _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 }