Author: baggins
Date: Wed Jul 27 14:40:17 2011
New Revision: 12282

Modified:
   xinitrc-ng/trunk/Xclients
Log:
- fix typo in wmstyledir setting
- rewritten whole logic, if we fail to run USERWM directly
  then try to find it by xsession file name and description name,
  if this fails repeat for DEFAULTWM
- eliminated sed and tr usage


Modified: xinitrc-ng/trunk/Xclients
==============================================================================
--- xinitrc-ng/trunk/Xclients   (original)
+++ xinitrc-ng/trunk/Xclients   Wed Jul 27 14:40:17 2011
@@ -5,7 +5,7 @@
 
 # Default values - may be redefined in $syswmfile
 userwmfile=".desktop"
-wmstyledir="/etc/sysconfig/wmstyles"
+wmstyledir="/etc/sysconfig/wmstyle"
 xsessdir="/usr/share/xsessions"
 DEFAULTWM=""
 
@@ -13,15 +13,56 @@
 unset USERWM WM_CHOICE
 
 loadsess()
-{      if [ -x "$HOME/bin/$WM_CHOICE.sh" ]; then
-               exec "$HOME/bin/$WM_CHOICE.sh"
-       elif [ -x "$wmstyledir/$WM_CHOICE.sh" ]; then
-               exec "$wmstyledir/$WM_CHOICE.sh"        
-       elif test `/usr/bin/which $WM_CHOICE 2>/dev/null`; then
-               eval "exec $WM_CHOICE"
+{
+       set -x
+       typeset runwm=$1
+
+       [ -z "$runwm" ] && return
+
+       if [ -x "$HOME/bin/$runwm.sh" ]; then
+               exec "$HOME/bin/$runwm.sh"
+       elif [ -x "$wmstyledir/$runwm.sh" ]; then
+               exec "$wmstyledir/$runwm.sh"
+       elif test `/usr/bin/which $runwm 2>/dev/null`; then
+               eval "exec $runwm"
        fi
 }
 
+findxsession()
+{
+       set -x
+       typeset -l __XSESSION=$1
+       typeset progname=""
+
+       if [ ! -d "$xsessdir" ]; then
+               echo "$xsessdir not found - check Your settings." >&2
+               return
+       fi      
+       for f in $xsessdir/*.desktop; do
+               typeset -l sessfile sessname altnames
+               sessfile=$(basename $f .desktop)
+               sessname=$(grep "^Name=" $f)
+               sessname=${sessname##name=}
+               if [ "$sessname" = "$__XSESSION" -o "$sessfile" = "$__XSESSION" 
]; then
+                       progname=$(grep "^Exec=" $f)
+                       progname=${progname##Exec=}
+                       break
+               fi
+               altnames=$(grep "^X-AltNames=" $f)
+               altnames=${altnames##x-altnames=}
+               oldIFS=$IFS ; IFS=";"; set -- $altnames ; IFS=$oldIFS
+               altnames="$*" 
+               for n in $altnames; do
+                       if [ "$n" = "$__XSESSION" ]; then
+                               progname=$(grep "^Exec=" $f)
+                               progname=${progname##Exec=}
+                               break
+                       fi
+               done
+       done
+       echo $progname
+}
+
 [ -f $syswmfile ] && . $syswmfile    
 
 # HOME_ETC support
@@ -36,40 +77,25 @@
        userwmfilefp="$HOME/.wm_style"
 fi     
 
-[ -f $userwmfilefp ] && USERWM=`cat $userwmfilefp |grep -v ^# |head -n 1`
+[ -f $userwmfilefp ] && USERWM=`grep -v "^#" $userwmfilefp | head -n 1`
 
 # Evaluate cmdline first
 [ -n "$*" ] && USERWM="$*"
 
 if [ -n "$USERWM" ]; then
         # Tray to run literal user choice first
-       WM_CHOICE=$USERWM
-       loadsess
+       loadsess $USERWM
        # if it fails - take another actions
-       WM_CHOICE=""
-       if [ ! -d "$xsessdir" ]; then
-               echo "$xsessdir not found - check Your settings."
-               exit 1
-       fi      
-       for f in $xsessdir/*.desktop; do
-               if [ "`cat $f |grep ^Name= |sed -e 's/Name=//' |tr A-Z a-z`" = 
"`echo $USERWM |tr A-Z a-z`" ]; then
-                       WM_CHOICE=`cat $f |grep ^Exec= |sed -e 's/Exec=//'`
-                       break
-               fi
-               for g in `cat $f |grep ^X-AltNames= |sed -e 's/X-AltNames=//' 
-e 's/;/ /g'`; do
-                       if [ "`echo $g |tr A-Z a-z`" = "`echo $USERWM |tr A-Z 
a-z`" ]; then
-                               WM_CHOICE=`cat $f |grep ^Exec= |sed -e 
's/Exec=//'`
-                               break 2
-                       fi
-               done
-       done             
+       WM_CHOICE=$(findxsession $USERWM)
        if [ -z "$WM_CHOICE" ]; then
-               echo "Sorry - nothing known about $USERWM"
-               echo "Resuming with system defaults..."
+               echo "Sorry - nothing known about $USERWM" >&2
+               echo "Resuming with system defaults..." >&2
                WM_CHOICE=$DEFAULTWM
        fi      
-else
-        WM_CHOICE=$DEFAULTWM
 fi
 
-[ -n "$WM_CHOICE" ] && loadsess || exec xterm
+loadsess $DEFAULTWM
+WM_CHOICE=$(findxsession $DEFAULTWM)
+
+loadsess $WM_CHOICE
+exec xterm
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to