2013-09-12 22:14:29 +02:00
|
|
|
|
#! /bin/bash
|
|
|
|
|
#
|
|
|
|
|
# bspwm-session
|
|
|
|
|
#
|
|
|
|
|
# This script is a session launcher for bspwm.
|
|
|
|
|
# It is based on similar scripts included with Openbox.
|
|
|
|
|
|
|
|
|
|
if [ -n "$1" ]; then
|
2014-01-21 20:51:02 +01:00
|
|
|
|
echo "Usage: bspwm-session"
|
|
|
|
|
echo
|
|
|
|
|
exit 1
|
2013-09-12 22:14:29 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Multi-user support:
|
|
|
|
|
state_prefix=${XDG_CACHE_HOME:-"$HOME/.cache"}
|
|
|
|
|
mkdir -p "${state_prefix}"
|
|
|
|
|
|
|
|
|
|
if [ ! -d "${state_prefix}" ]; then
|
2014-01-21 20:51:02 +01:00
|
|
|
|
echo "bspwm-session: cache directory ‘${state_prefix}‘ is missing."
|
|
|
|
|
echo
|
|
|
|
|
exit 1
|
2013-09-12 22:14:29 +02:00
|
|
|
|
elif [ ! -w "${state_prefix}" ]; then
|
2014-01-21 20:51:02 +01:00
|
|
|
|
echo "bspwm-session: cache directory ‘${state_prefix}‘ is not writable."
|
|
|
|
|
echo
|
|
|
|
|
exit 1
|
2013-09-12 22:14:29 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
state_path=$(mktemp -d "${state_prefix}/bspwm-session.XXXXXX")
|
|
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
2014-01-21 20:51:02 +01:00
|
|
|
|
echo "bspwm-session: failed to create state directory ‘${state_path}‘."
|
|
|
|
|
echo
|
|
|
|
|
exit 1
|
2013-09-12 22:14:29 +02:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
export BSPWM_SOCKET=${state_path}/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 {
|
2014-01-21 20:51:02 +01:00
|
|
|
|
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}"
|
2013-09-12 22:14:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap on_exit EXIT SIGHUP SIGINT SIGTERM
|
|
|
|
|
|
|
|
|
|
# Environment and autostart:
|
|
|
|
|
source_these=(
|
2014-01-21 20:51:02 +01:00
|
|
|
|
"/etc/profile",
|
|
|
|
|
"${HOME}/.profile",
|
|
|
|
|
"${XDG_CONFIG_HOME:-"$HOME/.config"}/bspwm/autostart"
|
2013-09-12 22:14:29 +02:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for file in "${source_these[@]}"; do
|
2014-01-21 20:51:02 +01:00
|
|
|
|
[ -r "${file}" ] && . "${file}"
|
2013-09-12 22:14:29 +02:00
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Launch sxhkd:
|
2013-12-01 11:33:08 +01:00
|
|
|
|
sxhkd &
|
2013-09-12 22:14:29 +02:00
|
|
|
|
|
|
|
|
|
# Launch bspwm:
|
2013-11-07 14:28:39 +01:00
|
|
|
|
bspwm
|