From 0dd8f62fc008daf6e4bdea568475d6f81bc08e5e Mon Sep 17 00:00:00 2001 From: Mehdi Sadeghi Date: Sun, 29 Aug 2021 21:07:34 +0200 Subject: Trap and kill leftover process. With the current i3status wrapper script, after exiting sway two process where left dangling out there. The i3status process and parts of the wrapper pipeline. Using set -eo pipefail and using shell substition and trapping fixed the problem. Note that this is a bash-only solution. --- .local/bin/any_position_wrapper.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to '.local/bin/any_position_wrapper.sh') diff --git a/.local/bin/any_position_wrapper.sh b/.local/bin/any_position_wrapper.sh index 6aa6268..f821657 100755 --- a/.local/bin/any_position_wrapper.sh +++ b/.local/bin/any_position_wrapper.sh @@ -1,4 +1,5 @@ #!/usr/bin/env bash +set -eo pipefail # This i3status wrapper allows to add custom information in any position of the statusline # It was developed for i3bar (JSON format) @@ -46,10 +47,12 @@ function irdate { json_array=$(update_holder holder__jdate "$json") } -i3status | (read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true +i3status > >(read line; echo "$line"; read line ; echo "$line" ; read line ; echo "$line" ; while true do read line json_array="$(echo $line | sed -e 's/^,//')" irdate echo ",$json_array" -done) +done) & PID=$! +trap "kill -TERM $PID" 0 1 2 15 +wait $PID -- cgit v1.2.3