1
0
Fork 0
dotfiles/.local/libexec/dwm/autorun
2024-02-08 17:04:57 +01:00

36 lines
799 B
Bash
Executable file

#!/bin/sh
trap 'kill $pids $(pidof xcape) 1>/dev/null 2>&1' 2 15 EXIT
LOGFILE="${LOGFILE:-${HOME}/.local/log/session-$(date -I).log}"
infolog() {
while IFS= read -r line; do
printf "%b" "[$(date +%X)][INF][$1]\t$line\n" >>"${LOGFILE}"
done
}
errorlog() {
while IFS= read -r line; do
printf "%b" "[$(date +%X)][ERR][$1]\t$line\n" >>"${LOGFILE}"
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