DSL Tips and Tricks :: Startup Configs



My .xinitrc

I've been tweaking my .xinitrc file for months, and part of it was posted above. Now I've got it at a point where I think the main future changes will be just adding more content rather than features (but then, who knows...), and thought i'd post what it looks like at present.  You SHOULD NOT just toss it into $HOME and expect anything from it...the result of this would likely be breakage of several applications' configurations, and many error messages.  I'm just posting it here as an example of what CAN be done.  If you were to use this script, you should read it and thoroughly understand what it's doing.  I won't be held responsible for killing your system =o)

Code Sample
#!/bin/sh
# Seriously hacked .xinitrc file from DSL 2.1b
############################################################
# NOTES ABOUT CHANGES IN THIS SCRIPT                       #
# The "#!/bin/sh" is not needed...just added so            #
# i could get proper syntax highlighting in Vim            #
#                                                          #
# Some external files implemented (not in DSL base):       #
# * Fluxbox themes and images in $HOME/.fluxbox.           #
# * $HOME/.fluxbox/{init-dev,keys-dev} for Fluxbox devel.  #
# * Irssi themes in $HOME/.irssi/themes.                   #
# * Xmms skins in $HOME/.xmms/Skins.                       #
# * IceWM themes in $HOME/.icewm/themes.                   #
# * $HOME/.xtheme (contains just the name of the theme).   #
# * Various window managers installed or mounted in /opt.  #
# * root-tail installed somewhere in $PATH.                #
# * Symlinks to aterm named "terminal" & "mc-term".        #
# * $HOME/.bashprompt, used by .bashrc.                    #
# * $HOME/.Xmodmap used to set keysyms for windows keys.   #
# * $HOME/windowmanager.log used to save output from wm.   #
# * Artwiz fonts (specifically "snap" and "lime").         #
#                                                          #
# Other things needed for proper behavior:                 #
# * Apps using the themes above have a generic symlink in  #
#   their configs.  For example, the styleFile listed in   #
#   the Fluxbox init files is the symlink "mystyle".       #
# * $HOME/.desktop contains only the name of the WM.       #
# * chmod 644 /var/log/messages (bootlocal.sh).            #
# * Start syslogd (boot parameter "syslog").               #
############################################################

# In case everything goes wrong, fall back to aterm.
trap "exec terminal" EXIT SIGHUP SIGINT SIGPIPE SIGTERM SIGIO

xmodmap $HOME/.Xmodmap
export TERM=xterm
# Turn off bell and add some fonts to font path
xset b off +fp $HOME/.fonts

# Find out what window manager to run
# I don't use icons, so i went back to the DSL2.0 method.
# This will probably get broken if you use the desktop switcher.
# I prefer this method because i can type echo fluxbox > .desktop
#    instead of echo "wm: fluxbox" > .desktop
DESKTOP=`cat .desktop`

# Default DSL stuff that i don't use
############################################################
#KEYTABLE="$(getknoppixparam.lua KEYTABLE)"
#DESKTOP=$(getoption.lua $HOME/.desktop wm)
#ICONS="$(getoption.lua $HOME/.desktop icons)"

# For German Keyboards
#if [ $KEYTABLE == "de" ]; then
#  xmodmap -e "clear Mod4" -e "add Mod5 = Mode_switch" &
#fi

#if egrep -qv noicons /proc/cmdline 2>/dev/null; then
#if [ "$ICONS" == 1 ]; then
#  for x in `ls -1 .xtdesktop/*.hide 2>/dev/null`; do rm -f ${x%.*}; done
#  iconsnap.lua &>/dev/null &
#  xtdesk &>/dev/null &
#fi
#dillo /usr/share/doc/dsl/getting_started.html &>/dev/null &
# torsmo 2>/dev/null &
############################################################

# set up a color scheme for X apps according to what is set in
# the $HOME/.xtheme file. This will OVERWRITE the .Xdefaults
# file, and sets environment variables for root-tail to use.
# If there is no .xtheme file, it will set grayscale colors.
#   BGCOLOR/FGCOLOR/CURSORCOLOR used by aterm
#   ROOTTAIL_COLOR<n> used to set root-tail color for each log file it tails
#   PS1_COLOR is the color used for the bash prompt
#   *_THEME is the theme that will be used for each application listed
#   PAPER is the wallpaper image used for WMs that cannot set it themselves
THEME=`cat $HOME/.xtheme 2>/dev/null`
case $THEME in
tan)
BGCOLOR=black
FGCOLOR=tan
CURSORCOLOR=sienna
ROOTTAIL_COLOR1=tan
ROOTTAIL_COLOR2=moccasin
ROOTTAIL_COLOR3=sienna
ROOTTAIL_COLOR4=beige
PS1_COLOR='\[\033[0;37m\]'
IRSSI_THEME=shrike
FLUX_THEME=iloveuci
XMMS_THEME=Arsinoe
ICE_THEME=PHOENIX/default.theme
PAPER=$HOME/.fluxbox/backgrounds/iloveuci.png
;;
green)
BGCOLOR=black
FGCOLOR=green2
CURSORCOLOR=LimeGreen
ROOTTAIL_COLOR1=MediumSeaGreen
ROOTTAIL_COLOR2=PaleGreen4
ROOTTAIL_COLOR3=SeaGreen
ROOTTAIL_COLOR4=green4
PS1_COLOR='\[\033[0;32m\]'
IRSSI_THEME=xmas
FLUX_THEME=mik-green
XMMS_THEME=detone_green
ICE_THEME=junglox/default.theme
PAPER=$HOME/.fluxbox/backgrounds/protist_green.jpg
;;
fire)
BGCOLOR=black
FGCOLOR=orange1
CURSORCOLOR=red4
ROOTTAIL_COLOR1=red4
ROOTTAIL_COLOR2=DarkOrange4
ROOTTAIL_COLOR3=tomato4
ROOTTAIL_COLOR4=orange4
PS1_COLOR='\[\033[0;31m\]'
IRSSI_THEME=roses
FLUX_THEME=firepenguin
XMMS_THEME=fyre
PAPER=$HOME/.fluxbox/backgrounds/firepenguin.jpg
;;
*)
BGCOLOR=black
FGCOLOR=gray99
CURSORCOLOR=gray60
ROOTTAIL_COLOR1=gray70
ROOTTAIL_COLOR2=gray60
ROOTTAIL_COLOR3=gray50
ROOTTAIL_COLOR4=gray40
PS1_COLOR='\[\033[1;30m\]'
IRSSI_THEME=bork
FLUX_THEME=Simpler
ICE_THEME=MajesticOS12/default.theme
XMMS_THEME=blak
PAPER=$HOME/.fluxbox/backgrounds/thinklinux1024.jpg
;;
esac

# root-tail is started from a function so i can
# easily plug it into arbitrary window managers
start_roottail() {
# The log file needs to be present for root-tail to work
touch $HOME/windowmanager.log
root-tail --noinitial --wordwrap --fork --whole \
--font $ROOTTAIL_FONT --color $ROOTTAIL_COLOR1 \
--cont-color $CURSORCOLOR --geometry $ROOTTAIL_GEOM \
$HOME/windowmanager.log,$ROOTTAIL_COLOR1,'windowmanager' \
/var/log/messages,$ROOTTAIL_COLOR4,'syslog'
}

# Set up some applications according to which WM was chosen
#   WM is the window manager
#   TOOLBAR is where terminal will be placed relative to bottom of screen
#   ROOTTAIL_* used for the placement and font of root-tail
# If a selected WM is not currently mounted, fall back to fluxbox
case $DESKTOP in
 fluxbox)
   WM=fluxbox
#    fluxter &>/dev/null &
#    docked.lua &
#    swallow.sh docked &
   TOOLBAR=24
   ROOTTAIL_FONT=snap
   ROOTTAIL_GEOM='512x384+4+0'
   start_roottail &
 ;;
 jwm)
   WM=jwm
   xsri --color=$BGCOLOR --emblem=$PAPER
   TOOLBAR=32
   ROOTTAIL_FONT=fixed
   ROOTTAIL_GEOM='512x384+4+0'
   start_roottail &
 ;;
 fluxdev)
   WM="/opt/fluxbox_0.9.14/bin/fluxbox -rc $HOME/.fluxbox/init-dev"
   [ -x "$WM" ] || WM=fluxbox
   TOOLBAR=24
   ROOTTAIL_FONT=snap
   ROOTTAIL_GEOM='512x384+4+0'
   start_roottail &
 ;;
 evilwm)
   WM="/opt/evilwm/evilwm -term aterm -bg $BGCOLOR -fg $FGCOLOR"
   [ -x "$WM" ] || WM=fluxbox
   xsetroot -cursor_name left_ptr
   #xsri --color=$BGCOLOR --emblem=$PAPER
   xsri --set $PAPER
   aterm -g 45x8-0-0 &
   TOOLBAR=0
   ROOTTAIL_FONT=lime
   ROOTTAIL_GEOM='1000x700+12+30'
   start_roottail &
 ;;
   icewm)
   WM=/opt/icewm/starticewm
   [ -x "$WM" ] || WM=fluxbox
   TOOLBAR=32
   ROOTTAIL_FONT=snap
   ROOTTAIL_GEOM='512x384+4+0'
   start_roottail &
 ;;
 * )
   WM=aterm
   xsri --color2=$CURSORCOLOR --color=black
 ;;
esac

# misc theme-related stuff using the variables set in "case $THEME".
# if a file is readable, link it to the default theme file
[ -r "$HOME/.fluxbox/styles/$FLUX_THEME" ] && ln -sf $HOME/.fluxbox/styles/{$FLUX_THEME,mystyle}
[ -r "$HOME/.irssi/themes/$IRSSI_THEME.theme" ] && ln -sf $HOME/.irssi/themes/{$IRSSI_THEME,default}.theme
[ -r "$HOME/.xmms/Skins/$XMMS_THEME.tar.bz2" ] && ln -sf $HOME/.xmms/Skins/{$XMMS_THEME,skin}.tar.bz2
[ -n "$ICE_THEME" ] && echo "Theme=\"$ICE_THEME\"" >$HOME/.icewm/theme
# write the .bashprompt file using an appropriate color
echo "$PS1_COLOR( o_\n/ >) [\w]\[\033[0m\]\n" >$HOME/.bashprompt

# put Xdefaults stuff here
cat << EOF > $HOME/.Xdefaults
! THIS FILE IS AUTOMATICALLY GENERATED BY .xinitrc
! EACH TIME X STARTS. DON'T BOTHER EDITING IT.

! DEFAULT ATERM
aterm*visualBell:true
aterm*background:$BGCOLOR
aterm*foreground:$FGCOLOR
aterm*cursorColor:$CURSORCOLOR
aterm*transparent:true
aterm*shading:50
aterm*font:fixed
aterm*saveLines:1000
aterm*colorMode:true
aterm*borderWidth:0
aterm*truetintingType:true
aterm*fading:80
aterm*geometry:120x50+150+42
aterm*scrollBar:False
aterm*termName:xterm

! RXVT
rxvt*visualBell:true
rxvt*background:$BGCOLOR
rxvt*foreground:$FGCOLOR
rxvt*cursorColor:$CURSORCOLOR
rxvt*transparent:true
rxvt*shading:50
rxvt*font:fixed
rxvt*colorMode:true
rxvt*borderWidth:0
rxvt*truetintingType:true
rxvt*fading:80
rxvt*geometry:80x25
rxvt*scrollBar:False
rxvt*termName:xterm

! other terminals, symlinks to aterm
! SMALL ATERM (link name: terminal)
terminal*geometry:80x25+0-$TOOLBAR
terminal*font: fixed
terminal*transparent:true
terminal*shading:50
terminal*fading:80
terminal*scrollBar:False
aterm*background:$BGCOLOR
terminal*foreground: $FGCOLOR
terminal*cursorColor:$CURSORCOLOR

! WIDE ATERM (link name: mc-term)
mc-term*geometry:120x25-0+0
mc-term*font: fixed
mc-term*transparent:true
mc-term*shading:50
mc-term*fading:80
mc-term*scrollBar:False
aterm*background:$BGCOLOR
mc-term*foreground: $FGCOLOR
mc-term*cursorColor:$CURSORCOLOR
EOF

exec $WM &>$HOME/windowmanager.log

I just had to add this topic to my bookmarks.  :cool:
mikshaw:

You seem to use that case-statement sometimes...

Like here:
Quote
THEME=`cat ./.xtheme`

case $THEME in
tan)
BGCOLOR=black
FGCOLOR=tan
CURSORCOLOR=sienna
;;
fire)
BGCOLOR=black
FGCOLOR=orange1
CURSORCOLOR=red4
;;
*)
BGCOLOR=black
FGCOLOR=gray90
CURSORCOLOR=gray60
;;
esac


I haven't used it but if I understand it is annother way to do if-statement where two values are compared and if it is true then perform commands.
More simplier: if-statement with only '=' operator. And the other value never changes.

I'm not sure how that would be simpler.
The above code translated to "if" would be this:
Code Sample
THEME=`cat ./.xtheme`

if "$THEME" == "tan"; then
BGCOLOR=black
FGCOLOR=tan
CURSORCOLOR=sienna
elif "$THEME" == "fire"; then
BGCOLOR=black
FGCOLOR=orange1
CURSORCOLOR=red4
else
BGCOLOR=black
FGCOLOR=gray90
CURSORCOLOR=gray60
fi


From my point of view, it is redundant, larger, and more difficult to read, particularly if you end up needing nested "if" statements.

It accomplishes the same task, but I tend to use "if" only for unique comparisons.  If a single value is compared to several options, case is more appropriate in my opinion.

BTW, I haven't used that script for quite a while.  I still have it for those occasions where I want to quickly re-theme my X environment, but mostly I just use a simple script that starts root-tail and my window manager.

I got intrested when I just read somewhere that case supports wildcards too. =)
Next Page...
original here.