From b0d0d2c8ff9b55d29f0cb08add19410a14daf048 Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 12 Feb 2017 16:55:23 +0100 Subject: [PATCH] Fix several issues with .xinitrc --- .xinitrc | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/.xinitrc b/.xinitrc index b9eb3b5..2828351 100755 --- a/.xinitrc +++ b/.xinitrc @@ -1,14 +1,33 @@ [ -f ~/.xprofile ] && . ~/.xprofile [ -f ~/.setpath.sh ] && . ~/.setpath.sh -DEFAULT_SESSION=qtile +AUTHORISED_WM="qtile i3" +AVAILABLE_WM="" +REQUESTED_WM="$1" -case "$1" in - awesome) - exec awesome - ;; - qtile) - exec qtile 2>/tmp/qtile.err.log - ;; - *) exec $DEFAULT_SESSION ;; -esac +for wm in $AUTHORISED_WM; do + if hash "$wm" 2>/dev/null; then + if [ "$AVAILABLE_WM" ]; then + AVAILABLE_WM="$AVAILABLE_WM $wm" + else + AVAILABLE_WM="$wm" + fi + fi +done +if [ ! "$AVAILABLE_WM" ]; then + >&2 echo "Error: No window manager found. Please install one of the following:" + >&2 echo "$AUTHORISED_WM" + exit 1 +fi + +WM=$(echo "$AVAILABLE_WM" | tr ' ' '\n' | head -n1) +if [ "$REQUESTED_WM" ]; then + found=$(echo "$AVAILABLE_WM" | tr ' ' '\n' | grep -w "$REQUESTED_WM") + if [ "$found" ]; then + WM="$found" + else + >&2 echo "Warning: $REQUESTED_WM not found, starting the default window manager." + fi +fi + +exec "$WM" 2>/tmp/xinit.err.log