- Improved rand():

make use of /dev/urandom instead /proc/uptime to become a random string.

- Eliminated $max_number:
  Themes do not need to conatin $max_number colors.
  Maximum number of xterms is not limited.

- $number was renamed in $many, to be more different to the counters.

- increased minor version
This commit is contained in:
heinzel
2003-10-13 11:17:20 +00:00
parent 742553d99f
commit f94b3fbf6e

View File

@@ -1,14 +1,13 @@
#!/bin/bash #!/bin/bash
# LOC ~/scripts/xtermmaker.sh # LOC ~/scripts/xtermmaker.sh
# CVS $Id: xtermmaker.sh,v 1.3 2003/02/19 12:54:18 heinzel Exp $ # CVS $Id: xtermmaker.sh,v 1.4 2003/10/13 11:17:20 heinzel Exp $
version='xtermmaker.sh Version 3.3 $Revision: 1.3 $ ($Date: 2003/02/19 12:54:18 $ $Author: heinzel $)' version='xtermmaker.sh Version 3.4 $Revision: 1.4 $ ($Date: 2003/10/13 11:17:20 $ $Author: heinzel $)'
### config ### ### config ###
xterm=xterm xterm=xterm
xterm_opts="-sb -sl 1024" xterm_opts="-sb -sl 1024"
number=1 many=1
max_number=9
rsh=ssh rsh=ssh
host="" host=""
@@ -16,12 +15,11 @@ user=""
color=RAND color=RAND
theme=light 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_traditional="SteelBlue,SeaGreen,orange,gold,tomato,CadetBlue,SlateGrey,MediumSeaGreen,Goldenrod"
theme_light="SlateGrey,MediumSeaGreen,Goldenrod,IndianRed,CadetBlue,DarkSeaGreen,khaki,CornflowerBlue,orange" 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 # if cols > 0, we arange the possitions of the xterms in $cols columns
cols=0 cols=0
@@ -40,13 +38,13 @@ print_version()
print_help() print_help()
{ {
cat <<E-O-H cat <<EOH
Usage: xtermmaker.sh [-n <number>] [-C <columns>] [-u <user>] [-r <host>] Usage: xtermmaker.sh [-n <number>] [-C <columns>] [-u <user>] [-r <host>]
[-c <color>] [-g] [-b] [-z] [--t <theme>] [-c <color>] [-g] [-b] [-z] [-t <theme>]
[-h,--help] [-V,--version] [-h,--help] [-V,--version]
-n Opens <number> xterms (default: $number) (max: $max_number). -n Opens <number> xterms (default: $number).
-C If specified, the xterms will be aranged in <columns> columns. -C If specified, the xterms will be aranged in <columns> columns.
-r Exec remote shell to the specified hostname. -r Exec remote shell to the specified hostname.
@@ -59,20 +57,19 @@ Usage: xtermmaker.sh [-n <number>] [-C <columns>] [-u <user>] [-r <host>]
-t Use color theme <theme> for 'Bunte XTerms'. -t Use color theme <theme> for 'Bunte XTerms'.
Possible themes: $themes (default: $theme) Possible themes: $themes (default: $theme)
E-O-H EOH
} }
rand() rand()
{ {
# Usage: rand <int> # Usage: rand <int>
local i="${1:-1}" local i="${1:-1}"
local f=/proc/uptime local f="/dev/urandom"
local b="" local b=""
local p=0 local p=0
b=`md5sum $f | tr -d "[:alpha:] [:punct:]"` b="`dd if=\"$f\" bs=8 count=1 2>/dev/null | md5sum | \
p=`expr ${#b} - 1` tr -d \"[:alpha:] [:punct:]\" | cut -c-2`"
b=`echo $b | cut -c ${p}-`
expr \( $b \* $i \) / 100 + 1 expr \( $b \* $i \) / 100 + 1
} }
@@ -92,7 +89,7 @@ while test $# -gt 0 ; do
exit 0 exit 0
;; ;;
-n|-number|--number) -n|-number|--number)
number="$2" many="$2"
shift shift
shift shift
;; ;;
@@ -138,28 +135,35 @@ done
### action ### ### action ###
test "$number" || number=1 test "$many" || number=1
test "$number" -le "$max_number" || number=$max_number
# position of the first window # position of the first window
column=1 column=1
hpos="$hoffset" hpos="$hoffset"
vpos="$voffset" vpos="$voffset"
count=1 eval colors=\$theme_$theme
until test $count -gt $number ; do ncolors="`echo \"$colors\" | tr -d [[:alnum:]]`"
ncolors="${#ncolors}"
title_opt="-title $count" xterm_count=1
color_count=1
until test $xterm_count -gt $many ; do
title_opt="-title $xterm_count"
case "$color" in case "$color" in
BUNT) BUNT)
eval colors=\$theme_$theme bg_opt="-bg `echo $colors | cut -f $color_count -d ,`"
bg_opt="-bg `echo $colors | cut -f $count -d ,`" if test "$color_count" -le "$ncolors" ; then
color_count=`expr $color_count + 1`
else
color_count=1
fi
;; ;;
RAND) RAND)
eval colors=\$theme_$theme color_count=`rand $ncolors`
buf=`rand $max_number` bg_opt="-bg `echo $colors | cut -f $color_count -d ,`"
bg_opt="-bg `echo $colors | cut -f $buf -d ,`"
;; ;;
*) *)
bg_opt="-bg $color" bg_opt="-bg $color"
@@ -195,8 +199,7 @@ until test $count -gt $number ; do
fi fi
$xterm $xterm_opts $title_opt $bg_opt $fg_opt $pos_opt $exec_opt & $xterm $xterm_opts $title_opt $bg_opt $fg_opt $pos_opt $exec_opt &
xterm_count=`expr $xterm_count + 1`
count=`expr $count + 1`
done done
exit 0 exit 0