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-02-19 12:54:18 +00:00

203 lines
3.6 KiB
Bash
Executable File

#!/bin/bash
# LOC ~/scripts/xtermmaker.sh
# CVS $Id: xtermmaker.sh,v 1.3 2003/02/19 12:54:18 heinzel Exp $
version='xtermmaker.sh Version 3.3 $Revision: 1.3 $ ($Date: 2003/02/19 12:54:18 $ $Author: heinzel $)'
### config ###
xterm=xterm
xterm_opts="-sb -sl 1024"
number=1
max_number=9
rsh=ssh
host=""
user=""
color=RAND
theme=light
themes="traditional, light"
# NOTE: Themes MUST have $max_number colors defined
theme_traditional="SteelBlue,SeaGreen,orange,gold,tomato,CadetBlue,SlateGrey,MediumSeaGreen,Goldenrod"
theme_light="SlateGrey,MediumSeaGreen,Goldenrod,IndianRed,CadetBlue,DarkSeaGreen,khaki,CornflowerBlue,orange"
# 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 <<E-O-H
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) (max: $max_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)
E-O-H
}
rand()
{
# Usage: rand <int>
local i="${1:-1}"
local f=/proc/uptime
local b=""
local p=0
b=`md5sum $f | tr -d "[:alpha:] [:punct:]"`
p=`expr ${#b} - 1`
b=`echo $b | cut -c ${p}-`
expr \( $b \* $i \) / 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)
number="$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 "$number" || number=1
test "$number" -le "$max_number" || number=$max_number
# position of the first window
column=1
hpos="$hoffset"
vpos="$voffset"
count=1
until test $count -gt $number ; do
title_opt="-title $count"
case "$color" in
BUNT)
eval colors=\$theme_$theme
bg_opt="-bg `echo $colors | cut -f $count -d ,`"
;;
RAND)
eval colors=\$theme_$theme
buf=`rand $max_number`
bg_opt="-bg `echo $colors | cut -f $buf -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 &
count=`expr $count + 1`
done
exit 0