This repository has been archived on 2019-10-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
xtermmaker/xtermmaker.sh
2003-10-13 14:21:02 +00:00

206 lines
3.8 KiB
Bash
Executable File

#!/bin/bash
# LOC ~/scripts/xtermmaker.sh
# CVS $Id: xtermmaker.sh,v 1.7 2003/10/13 14:21:02 heinzel Exp $
version='XTermMaker Version 3.4 $Revision: 1.7 $ ($Date: 2003/10/13 14:21:02 $ $Author: heinzel $)'
### config ###
xterm=xterm
xterm_opts="-sb -sl 1024"
many=1
rsh=ssh
host=""
user=""
color=RAND
theme=light
theme_traditional="SteelBlue,SeaGreen,orange,gold,tomato,CadetBlue,SlateGrey,MediumSeaGreen,Goldenrod"
theme_light="SlateGrey,MediumSeaGreen,Goldenrod,IndianRed,CadetBlue,DarkSeaGreen,khaki,CornflowerBlue,orange"
theme_blay="lavender,DimGray,SlateGray,LightSlateGray,LightSteelBlue,SkyBlue,CornflowerBlue,SteelBlue"
themes="`set | grep "^theme_" | cut -f1 -d= | cut -c7- | tr '\n' ' '`"
# if cols > 0, we arange the possitions of the xterms in $cols columns
cols=0
hoffset=64
voffset=64
width=499
height=348
space=4
### functions ###
print_version()
{
echo "$version"
}
print_help()
{
cat <<EOH
Usage: xtermmaker.sh [-n <number>] [-C <columns>] [-u <user>] [-r <host>]
[-c <color>] [-g] [-b] [-z] [-t <theme>]
[-h,--help] [-V,--version]
-n Opens <number> xterms (default: $number).
-C If specified, the xterms will be aranged in <columns> columns.
-r Exec remote shell to the specified hostname.
-u Specifies the username for the remote host.
-c Set the backgroundcolor of the xterms.
-g Same as -c Gray.
-b Generates 'Bunte XTerms' in serial sequence.
-z Generates 'Bunte XTerms' in random sequence (default).
-t Use color theme <theme> for 'Bunte XTerms'.
Possible themes: $themes (default: $theme)
EOH
}
rand()
{
# Usage: rand <int>
local m="${1:-1}"
local f="/dev/urandom"
local n=""
n="`dd if=\"$f\" bs=8 count=1 2>/dev/null | md5sum | \
tr -d \"[:alpha:] [:punct:]\" | cut -c-2`"
expr \( $n \* $m \) / 100 + 1
}
### argv ###
# read arguments from stdin
while test $# -gt 0 ; do
case "$1" in
-h|-help|--help)
print_help
exit 0
;;
-V|-version|--version)
print_version
exit 0
;;
-n|-number|--number)
many="$2"
shift
shift
;;
-C|-cols|--cols)
cols="$2"
shift
shift
;;
-c|-color|--color)
color="$2"
shift
shift
;;
-g)
color=Gray
shift
;;
-b)
color=BUNT
shift
;;
-z)
color=RAND
shift
;;
-t|-theme|--theme)
theme="$2"
shift
shift
;;
-u|-user|--user)
user="$2"
shift
shift
;;
-r|-host|--host)
host="$2"
shift
shift
;;
esac
done
### action ###
test "$many" || number=1
# position of the first window
column=1
hpos="$hoffset"
vpos="$voffset"
eval colors=\$theme_$theme
ncolors="`echo \"$colors\" | tr -d [[:alnum:]]`"
ncolors="${#ncolors}"
ncolors="`expr $ncolors + 1`"
xterm_count=1
color_count=1
until test $xterm_count -gt $many ; do
title_opt="-title $xterm_count"
case "$color" in
BUNT)
bg_opt="-bg `echo $colors | cut -f $color_count -d ,`"
if test "$color_count" -lt "$ncolors" ; then
color_count=`expr $color_count + 1`
else
color_count=1
fi
;;
RAND)
color_count=`rand $ncolors`
bg_opt="-bg `echo $colors | cut -f $color_count -d ,`"
;;
*)
bg_opt="-bg $color"
;;
esac
fg_opt="-fg black"
if test "$cols" -gt 0 ; then
# position for this window
pos_opt="-geometry +${hpos}+${vpos}"
# calculate the position for the next window
if test "$column" -lt "$cols" ; then
# current column is less than max columns ->
# we can place the next window right of this one
column="`expr $column + 1`"
hpos="`expr $hpos + $width + $space`"
else
# we need a new row
column=1
hpos="$hoffset"
vpos="`expr $vpos + $height + $space`"
fi
else
pos_opt=""
fi
if test "$host" ; then
t=$host
test "$user" && t="${user}@${host}"
exec_opt="-e $rsh $t"
fi
$xterm $xterm_opts $title_opt $bg_opt $fg_opt $pos_opt $exec_opt &
xterm_count=`expr $xterm_count + 1`
done
exit 0