#!/bin/zsh
#
# bspwm-session
#
# This script is a session launcher for bspwm.
# It is based on similar scripts included with Openbox.

if [ -n "$1" ]; then
	echo "Usage: bspwm-session"
	echo
	exit 1
fi

# One socket per user
export BSPWM_SOCKET=$HOME/.cache/bspwm-socket

# Trap: make sure everything started in ~/.config/bspwm/autostart is
# signalled when this script exits or dies. Also clean up $state_path.
function on_exit {
	for child in $(jobs -p); do
		jobs -p | grep -q $child && kill $child
	done
	# Extra paranoia
	[[ -d "${state_path}" && -w "${state_path}" ]] && rm -rf -- "${state_path}"
}

trap on_exit EXIT SIGHUP SIGINT SIGTERM

# Environment and autostart:
source_these=(
	"/etc/profile"
	"${HOME}/.profile"
	"${XDG_CONFIG_HOME:-"$HOME/.config"}/bspwm/autostart"
)

for file in "${source_these[@]}"; do
	[ -r "${file}" ] && . "${file}"
done

# Launch sxhkd:
case $HOST in
    laptop) sxhkd ~/.config/sxhkd/laptop ~/.config/sxhkd/volume &;;
    home) sxhkd ~/.config/sxhkd/volume &;;
    hegp) sxhkd ~/.config/sxhkd/volume ~/.config/sxhkd/music &;;
    hegp-laptop) sxhkd ~/.config/sxhkd/volume & ~/.config/sxhkd/music ;;
esac

# Launch bspwm:
bspwm
