[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RP] script for cycling xterm colors
From: |
TJ Sellari |
Subject: |
[RP] script for cycling xterm colors |
Date: |
Sat Oct 4 18:53:11 2003 |
User-agent: |
Mutt/1.5.4i |
If anyone's interested, here's a script for cycling foreground colors when
opening xterms. I've bound it to C-t x on my machines. I find it's easier to
keep track of what I'm doing in different xterms if they're different
colors.
I'd recommend adding the line:
rm ~/xtermcounter ; touch ~/xtermcounter &
to your .xinitrc so you start from scratch each time you start X. See the
script for (a few) more details.
Tom
______________________________________________________________________
# switchterm.sh was written by T.J. Sellari for use with the Ratpoison
# window manager for X, though it should work with inferior, rodent-infested
# window managers as well. The script runs an xterm with a certain color
# foreground each time it is run, in a cycle of four foreground colors.
#
# The script uses a file in the user's home directory named xtermcounter.
# If your home directory already contains a file with this name, change the
# script or the filename.
############################ IMPORTANT ##################################
# For the script to work correctly in all (?) cases, you should add the
# following line to your .xinitrc:
# rm ~/xtermcounter ; touch ~/xtermcounter &
# If you want to use the script to start an xterm of your chosen color set
# by default whenever you start X, add the # following line instead:
# rm ~/xtermcounter ; touch ~/xtermcounter && ~/switchterm.sh &
#########################################################################
#!/bin/bash
# Choose four colors for xterm foregrounds:
COLOR1=ivory3
COLOR2=slateblue
COLOR3=seagreen2
COLOR4=goldenrod2
# Choose a background color:
BACKGROUND=black
# Name the file to record the number of running xterms of each color:
XTERMFILE=~/xtermcounter
# xtermcounter is created at the end of the script. The if/else statements
# test to see which color's next in line and sets that color for the next
# xterm that starts.
COLOR1XTERMS=`grep -c $COLOR1 $XTERMFILE`
COLOR2XTERMS=`grep -c $COLOR2 $XTERMFILE`
COLOR3XTERMS=`grep -c $COLOR3 $XTERMFILE`
COLOR4XTERMS=`grep -c $COLOR4 $XTERMFILE`
if [ $COLOR1XTERMS -le $COLOR2XTERMS ] ; then
NEXTXTERM=$COLOR1XTERMS
NEXTCOLOR=$COLOR1
else NEXTXTERM=$COLOR2XTERMS
NEXTCOLOR=$COLOR2
fi
if [ $COLOR3XTERMS -lt $NEXTXTERM ] ; then
NEXTXTERM=$COLOR3XTERMS
NEXTCOLOR=$COLOR3
fi
if [ $COLOR4XTERMS -lt $NEXTXTERM ] ; then
NEXTXTERM=$COLOR4XTERMS
NEXTCOLOR=$COLOR4
fi
# These four lines 1) add the name of the next color to the xtermcounter
# file, 2) run the appropriate color xterm, 3) move the xtermcounter file to
# a temporary file, and 4) after the xterm is closed, remove the name that
# was added to the file in step 1).
# Change the xterm line to suit your own preferences.
echo "$NEXTCOLOR">> $XTERMFILE &&
xterm -fn 8x16 -bg $BACKGROUND -fg $NEXTCOLOR &&
mv $XTERMFILE $XTERMFILE.tmp &&
sed -e "1s/$NEXTCOLOR//;t XXX" -e "1,/$NEXTCOLOR/s///" $XTERMFILE.tmp -e :XXX
-e '/^$/ d' > $XTERMFILE