2016-05-25 07:03:48 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
#set -eux
|
|
|
|
set -eu
|
|
|
|
set -o pipefail
|
2016-05-19 10:41:06 -04:00
|
|
|
|
|
|
|
[ $# -eq 0 ] && {
|
|
|
|
echo "No bar specified" ; exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
command -v lemonbar >/dev/null || {
|
|
|
|
echo "Lemonbar is not installed" ; exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
command -v lemonbuddy >/dev/null || {
|
|
|
|
echo "Lemonbuddy is not installed" ; exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
lemonbar="$(lemonbuddy "$@" -x)"
|
|
|
|
wmname="$(lemonbuddy "$@" -w)"
|
|
|
|
logfile="${XDG_CACHE_HOME:-$HOME/.cache}/lemonbuddy/${wmname}.log"
|
|
|
|
logdir="$(dirname "$logfile")"
|
|
|
|
pipe="$(mktemp -u /tmp/lemonbuddy.in.XXXXX)"
|
|
|
|
|
|
|
|
[ -d "$logdir" ] || mkdir -p "$logdir"
|
|
|
|
|
2016-05-25 08:48:37 -04:00
|
|
|
exec 2> >(tee "$logfile")
|
|
|
|
|
2016-05-19 10:41:06 -04:00
|
|
|
mkfifo "$pipe"
|
|
|
|
|
2016-05-25 07:03:48 -04:00
|
|
|
cleanup_proc() {
|
|
|
|
pid=$1
|
|
|
|
kill -0 "$pid" 2>/dev/null && {
|
|
|
|
echo "$pid is running (sending term signal)..."
|
2016-05-25 07:58:57 -04:00
|
|
|
kill -TERM "$pid" 2>/dev/null
|
2016-05-25 07:03:48 -04:00
|
|
|
}
|
2016-05-19 10:41:06 -04:00
|
|
|
}
|
|
|
|
|
2016-05-25 07:03:48 -04:00
|
|
|
# shellcheck disable=SC2094
|
2016-05-25 08:48:37 -04:00
|
|
|
{ lemonbuddy "$@" -p "$pipe"; kill -TERM $$ 2>/dev/null; } | $lemonbar >"$pipe" &
|
2016-05-19 10:41:06 -04:00
|
|
|
|
2016-05-25 07:03:48 -04:00
|
|
|
trap 'cleanup_proc $!' TERM INT
|
|
|
|
|
|
|
|
while kill -0 $! 2>/dev/null; do
|
|
|
|
sleep 0.5s
|
2016-05-19 10:41:06 -04:00
|
|
|
done
|
2016-05-25 07:03:48 -04:00
|
|
|
|
|
|
|
[ -e "$pipe" ] && rm "$pipe"
|
|
|
|
|
|
|
|
kill 0; wait
|