From f94b3fbf6e5e5362dd26bdebe2c0e6b098de6d57 Mon Sep 17 00:00:00 2001 From: heinzel Date: Mon, 13 Oct 2003 11:17:20 +0000 Subject: [PATCH] - 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 --- xtermmaker.sh | 59 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/xtermmaker.sh b/xtermmaker.sh index f0f16f7..6eb919e 100755 --- a/xtermmaker.sh +++ b/xtermmaker.sh @@ -1,14 +1,13 @@ #!/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 $)' +# CVS $Id: xtermmaker.sh,v 1.4 2003/10/13 11:17:20 heinzel Exp $ +version='xtermmaker.sh Version 3.4 $Revision: 1.4 $ ($Date: 2003/10/13 11:17:20 $ $Author: heinzel $)' ### config ### xterm=xterm xterm_opts="-sb -sl 1024" -number=1 -max_number=9 +many=1 rsh=ssh host="" @@ -16,12 +15,11 @@ 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" +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 @@ -40,13 +38,13 @@ print_version() print_help() { - cat <] [-C ] [-u ] [-r ] - [-c ] [-g] [-b] [-z] [--t ] + [-c ] [-g] [-b] [-z] [-t ] [-h,--help] [-V,--version] - -n Opens xterms (default: $number) (max: $max_number). + -n Opens xterms (default: $number). -C If specified, the xterms will be aranged in columns. -r Exec remote shell to the specified hostname. @@ -59,20 +57,19 @@ Usage: xtermmaker.sh [-n ] [-C ] [-u ] [-r ] -t Use color theme for 'Bunte XTerms'. Possible themes: $themes (default: $theme) -E-O-H +EOH } rand() { # Usage: rand local i="${1:-1}" - local f=/proc/uptime + local f="/dev/urandom" local b="" local p=0 - b=`md5sum $f | tr -d "[:alpha:] [:punct:]"` - p=`expr ${#b} - 1` - b=`echo $b | cut -c ${p}-` + b="`dd if=\"$f\" bs=8 count=1 2>/dev/null | md5sum | \ + tr -d \"[:alpha:] [:punct:]\" | cut -c-2`" expr \( $b \* $i \) / 100 + 1 } @@ -92,7 +89,7 @@ while test $# -gt 0 ; do exit 0 ;; -n|-number|--number) - number="$2" + many="$2" shift shift ;; @@ -138,28 +135,35 @@ done ### action ### -test "$number" || number=1 -test "$number" -le "$max_number" || number=$max_number +test "$many" || number=1 # position of the first window column=1 hpos="$hoffset" vpos="$voffset" -count=1 -until test $count -gt $number ; do +eval colors=\$theme_$theme +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 BUNT) - eval colors=\$theme_$theme - bg_opt="-bg `echo $colors | cut -f $count -d ,`" + bg_opt="-bg `echo $colors | cut -f $color_count -d ,`" + if test "$color_count" -le "$ncolors" ; then + color_count=`expr $color_count + 1` + else + color_count=1 + fi ;; RAND) - eval colors=\$theme_$theme - buf=`rand $max_number` - bg_opt="-bg `echo $colors | cut -f $buf -d ,`" + color_count=`rand $ncolors` + bg_opt="-bg `echo $colors | cut -f $color_count -d ,`" ;; *) bg_opt="-bg $color" @@ -195,8 +199,7 @@ until test $count -gt $number ; do fi $xterm $xterm_opts $title_opt $bg_opt $fg_opt $pos_opt $exec_opt & - - count=`expr $count + 1` + xterm_count=`expr $xterm_count + 1` done exit 0