]> git.donarmstrong.com Git - x_base.git/commitdiff
use cmd_exists and fork
authorDon Armstrong <don@donarmstrong.com>
Sun, 29 Oct 2017 04:14:42 +0000 (21:14 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 29 Oct 2017 04:14:42 +0000 (21:14 -0700)
.xsession

index b402817caebf2ff4dec895fd30c4a219d5843894..8ddaf1dcef90016da2286d0a478a007622c2e729 100755 (executable)
--- a/.xsession
+++ b/.xsession
@@ -1,5 +1,17 @@
 #!/bin/sh
 
 #!/bin/sh
 
+cmd_exists () {
+    if which "$1" >/dev/null 2>&1; then
+        return 0;
+    else
+        return 1;
+    fi;
+}
+
+fork () {
+    ( "$@" >/dev/null 2>&1 & )
+}
+
 echo "Starting new session"
 
 DATE=$(date "+%Y%m%d_%H%M%S")
 echo "Starting new session"
 
 DATE=$(date "+%Y%m%d_%H%M%S")
@@ -44,36 +56,38 @@ if [ -e ~/.Xauthority ]; then
     cp -f .Xauthority .Xauthority.bak
 fi
 
     cp -f .Xauthority .Xauthority.bak
 fi
 
-if [ -x /usr/bin/xscreensaver -a -e ~/.xscreensaver ]; then
-    ( XENVIRONMENT=~/.xscreensaver /usr/bin/xscreensaver >/dev/null 2>&1 &)
-elif [ -x /usr/bin/xautolock ]; then
-    (/usr/bin/xautolock -notifier true -bell 0 >/de/vnull 2>&1 &)
+if cmd_exists slock && cmd_exists xautolock; then
+    fork xautolock -notifer true -bell 0 -locker slock;
+elif cmd_exists xscreensaver && [ -e ~/.xscreensaver ]; then
+    fork XENVIRONMENT=~/.xscreensaver /usr/bin/xscreensaver;
+elif cmd_exists xautolock; then
+    fork xautolock -notifer true -bell 0;
 fi;
 
 fi;
 
-if which redshift >/dev/null 2>&1; then
-    (redshift >/dev/null 2>&1 &)
+if cmd_exists redshift; then
+    fork redshift;
 fi;
 
 fi;
 
-if which mopidy >/dev/null 2>&1 && [ -e ~/.config/mopidy/mopidy.conf ]; then
-    (mopidy > /dev/null 2>&1 & );
-elif which mpd >/dev/null 2>&1 && [ -e ~/.mpdconf ]; then
-    (mpd >/dev/null 2>&1 &);
+if cmd_exists mopidy && [ -e ~/.config/mopidy/mopidy.conf ]; then
+    fork mopidy;
+elif cmd_exists mpd && [ -e ~/.mpdconf ]; then
+    fork mpd;
     MPD_HOST=$(awk '/^bind_to_address/{print $2}' ~/.mpdconf|sed "s|~|$HOME|; s/^\"//; s/\"$//; ");
     export MPD_HOST;
 fi;
 
     MPD_HOST=$(awk '/^bind_to_address/{print $2}' ~/.mpdconf|sed "s|~|$HOME|; s/^\"//; s/\"$//; ");
     export MPD_HOST;
 fi;
 
-if [ -x /sbin/iw ] && which nm-applet >/dev/null 2>&1 && /sbin/iw list|grep -q '^Wiphy'; then
-    ( nm-applet > /dev/null 2>&1 & );
+if [ -x /sbin/iw ] && cmd_exists nm-applet && /sbin/iw list|grep -q '^Wiphy'; then
+    fork nm-applet;
 fi;
 
 fi;
 
-if [ -x /usr/bin/i3 ]; then
+if cmd_exists i3; then
     if [ -x ~/.config/i3/build_config.sh ]; then
         ~/.config/i3/build_config.sh;
     fi;
     exec /usr/bin/i3;
 else
     for prog in awesome ion3 openbox stterm st rxvt rxvt-unicode xterm; do
     if [ -x ~/.config/i3/build_config.sh ]; then
         ~/.config/i3/build_config.sh;
     fi;
     exec /usr/bin/i3;
 else
     for prog in awesome ion3 openbox stterm st rxvt rxvt-unicode xterm; do
-        if which $prog >/dev/null 2>&1; then
+        if cmd_exists $prog; then
             exec $(which $prog)
         fi
     done;
             exec $(which $prog)
         fi
     done;