From d6f6479f88a37f147240f0e0a1273a7450e15242 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Sat, 20 Oct 2018 17:07:28 -0500
Subject: [PATCH] .xinitrc: Refactor

---
 .xinitrc | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/.xinitrc b/.xinitrc
index b8870225..5a65797a 100755
--- a/.xinitrc
+++ b/.xinitrc
@@ -6,17 +6,33 @@
 # Distributed under terms of the MIT license.
 #
 
-# Set up our session target
-which i3 > /dev/null 2>&1 && export STARTUP="i3"
-which bspwm > /dev/null 2>&1 && export STARTUP="bspwm"
-[ -x "$HOME/.concession/conspiracy" ] && export STARTUP="$HOME/.concession/conspiracy"
+step_get_target() {
+	# Set up our session target
+	which i3 > /dev/null 2>&1 && export STARTUP="i3"
+	which bspwm > /dev/null 2>&1 && export STARTUP="bspwm"
+	[ -x "$HOME/.concession/conspiracy" ] && export STARTUP="$HOME/.concession/conspiracy"
+}
 
-# Execute Xsession stuff
-[ -r /etc/X11/Xsession ] && . /etc/X11/Xsession
+step_start_xsession() {
+	# Execute Xsession stuff
+	[ -r /etc/X11/Xsession ] && . /etc/X11/Xsession
+}
 
-# Do the do
-[ -z "${STARTUP+x}" ] || exec "$STARTUP"
+step_start_manual() {
+	# Execute our target directly
+	[ -z "${STARTUP+x}" ] || exec "$STARTUP"
+}
+
+main() {
+	# Set up the environment
+	step_get_target
+	# Execute our target
+	step_start_xsession # Through Xsession scripts, or...
+	step_start_manual # ...manually, if need be
+	# Or maybe just die, I guess
+	echo "Failed to start session" >&2
+	exit 1
+}
+
+main $@
 
-# Or maybe just die, I guess
-echo "Failed to start Concession!" >&2
-exit 1