+_start() {
+ $TMUX new-session -d -s "$SESSION"
+ $TMUX set-option -gt "$SESSION" allow-rename off
+
+ _counter_file=$(mktemp)
+ launch_from_directory ~/.xlaunch.d
+ launch_from_directory ~/.xlaunch.d."$(hostname)"
+}
+
+_startx() {
+ log '[info] Starting X11'
+ _restart
+ log '[info] Launching dwm'
+ exec dwm
+}
+
+_stop() {
+ $TMUX kill-session -t "$SESSION"
+}
+
+_restart() {
+ _stop || true
+ _start
+}
+
+_attach() {
+ $TMUX attach -t "$SESSION"
+}
+
+main() {
+ local -r command="$1"
+
+ case "$command" in
+ #'' ) _startx;;
+ 'startx' ) _startx;;
+ 'start' ) _start;;
+ 'stop' ) _stop;;
+ 'restart' ) _restart;;
+ 'attach' ) _attach;;
+ *)
+ echo "[error] Unknown command: \"$command\". Known: startx, start, stop, restart, attach."
+ exit 1;;
+ esac
+}