1
0
Fork 0
dotfiles/.local/libexec/dwm/autorun

37 lines
799 B
Text
Raw Normal View History

2024-02-07 16:20:29 +01:00
#!/bin/sh
2024-02-08 17:04:57 +01:00
trap 'kill $pids $(pidof xcape) 1>/dev/null 2>&1' 2 15 EXIT
2024-02-07 16:20:29 +01:00
2024-02-08 17:04:57 +01:00
LOGFILE="${LOGFILE:-${HOME}/.local/log/session-$(date -I).log}"
2024-02-07 16:20:29 +01:00
infolog() {
while IFS= read -r line; do
2024-02-08 17:04:57 +01:00
printf "%b" "[$(date +%X)][INF][$1]\t$line\n" >>"${LOGFILE}"
2024-02-07 16:20:29 +01:00
done
}
errorlog() {
while IFS= read -r line; do
2024-02-08 17:04:57 +01:00
printf "%b" "[$(date +%X)][ERR][$1]\t$line\n" >>"${LOGFILE}"
2024-02-07 16:20:29 +01:00
done
}
start() {
stdout="${XDG_RUNTIME_DIR:-/tmp}/${1}-stdout"
stderr="${XDG_RUNTIME_DIR:-/tmp}/${1}-stderr"
[ -p "$stdout" ] || mkfifo "$stdout"
[ -p "$stderr" ] || mkfifo "$stderr"
cat <"$stdout" | infolog "$1" &
cat <"$stderr" | errorlog "$1" &
pidof -sx "$1" || "./$1" >"$stdout" 2>"$stderr" &
}
cd "$HOME/.local/libexec/dwm/autorun.d" || exit 1
for s in *; do
start "$s"
pids="$! $pids"
done
wait