]> git.lizzy.rs Git - bspwm.git/blob - contrib/freedesktop/bspwm-session
Merge pull request #281 from fbergroth/leaf-monocle
[bspwm.git] / contrib / freedesktop / bspwm-session
1 #! /bin/bash
2 #
3 # bspwm-session
4 #
5 # This script is a session launcher for bspwm.
6 # It is based on similar scripts included with Openbox.
7
8 if [ -n "$1" ]; then
9         echo "Usage: bspwm-session"
10         echo
11         exit 1
12 fi
13
14 # Multi-user support:
15 state_prefix=${XDG_CACHE_HOME:-"$HOME/.cache"}
16 mkdir -p "${state_prefix}"
17
18 if [ ! -d "${state_prefix}" ]; then
19         echo "bspwm-session: cache directory ‘${state_prefix}‘ is missing."
20         echo
21         exit 1
22 elif [ ! -w "${state_prefix}" ]; then
23         echo "bspwm-session: cache directory ‘${state_prefix}‘ is not writable."
24         echo
25         exit 1
26 fi
27
28 state_path=$(mktemp -d "${state_prefix}/bspwm-session.XXXXXX")
29
30 if [ $? -ne 0 ]; then
31         echo "bspwm-session: failed to create state directory ‘${state_path}‘."
32         echo
33         exit 1
34 fi
35
36 export BSPWM_SOCKET=${state_path}/bspwm-socket
37
38 # Trap: make sure everything started in ~/.config/bspwm/autostart is
39 # signalled when this script exits or dies. Also clean up $state_path.
40 function on_exit {
41         for child in $(jobs -p); do
42                 jobs -p | grep -q $child && kill $child
43         done
44         # Extra paranoia
45         [[ -d "${state_path}" && -w "${state_path}" ]] && rm -rf -- "${state_path}"
46 }
47
48 trap on_exit EXIT SIGHUP SIGINT SIGTERM
49
50 # Environment and autostart:
51 source_these=(
52         "/etc/profile"
53         "${HOME}/.profile"
54         "${XDG_CONFIG_HOME:-"$HOME/.config"}/bspwm/autostart"
55 )
56
57 for file in "${source_these[@]}"; do
58         [ -r "${file}" ] && . "${file}"
59 done
60
61 # Launch sxhkd:
62 sxhkd &
63
64 # Launch bspwm:
65 bspwm