1
0
Fork 0
dotfiles/.config/dwm/start.sh

37 lines
925 B
Bash
Executable File

#!/bin/sh
# This script is used by DWM to start programs when it starts
# It's meant as a sort of wrapper script to start a long running program and have it log to a file.
# Some examples:
# env LOGFILE=~/test.log start pipewire
# start pipewire; tail -f ~/.local/log/pipewire.log
LOGFILE="${LOGFILE:-${HOME}/.local/log/${1}.log}"
BOLD="$(tput bold)"
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
NC="$(tput sgr0)"
infolog() {
while IFS= read -r line; do
echo "[$(date +%X)][${BOLD}${GREEN}INF${NC}][$1] $line" >>"${LOGFILE}"
done
}
errorlog() {
while IFS= read -r line; do
echo "[$(date +%X)][${BOLD}${RED}ERR${NC}][$1] $line" >>"${LOGFILE}"
done
}
stdout="$XDG_RUNTIME_DIR/dwm-stdout"
stderr="$XDG_RUNTIME_DIR/dwm-stderr"
[ -p "$stdout" ] || mkfifo "$stdout"
[ -p "$stderr" ] || mkfifo "$stderr"
cat <"$stdout" | infolog "$1" &
cat <"$stderr" | errorlog "$1" &
pidof -sx "$1" || "$@" >"$stdout" 2>"$stderr"