1
0
Fork 0
dotfiles/.local/libexec/dwm/autorun
2024-02-07 16:20:29 +01:00

36 lines
778 B
Bash
Executable file

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