summaryrefslogtreecommitdiff
path: root/.local
diff options
context:
space:
mode:
authorMehdi Sadeghi <mehdi@mehdix.org>2021-08-29 21:07:34 +0200
committerMehdi Sadeghi <mehdi@mehdix.org>2021-08-29 21:07:34 +0200
commit0dd8f62fc008daf6e4bdea568475d6f81bc08e5e (patch)
tree9907c17549726bdb2a31b7205a84f9c292a288d0 /.local
parenteac660293c025232b7e45a392bbdf5b19af72331 (diff)
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.
Diffstat (limited to '.local')
-rwxr-xr-x.local/bin/any_position_wrapper.sh7
1 files changed, 5 insertions, 2 deletions
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