pan-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pan-users] Re: Shortcuts gone?


From: Duncan
Subject: [Pan-users] Re: Shortcuts gone?
Date: Thu, 17 Aug 2006 16:18:46 +0000 (UTC)
User-agent: pan 0.108 (Mama's Little Joyboy Loves Lobsters, Lobsters)

"Mick Semb Wever" <address@hidden> posted
address@hidden, excerpted below, on  Thu, 17 Aug 2006 12:51:17
+0000:

> It's a bash script printing out random quotes.
> The section that outputs the text is:
> 
> echo "-- "
> echo "${quotes[$RANDOM_NUMBER]}"
> echo "Homepage - www.wever.org" 
> echo "Sesam Search Engine - www.sesam.no"
> 
> So it's the ${quotes[$RANDOM_NUMBER]} that comes out in one line.
> There's probably a way of wrapping it in the bash script as well but my
> scripting ability isn't good enough to know.

There is.  It would involve ${#var}, which returns the number of chars in
string $var, possibly ${var:n:l}, which returns a substring starting at
position n (zero-based), length l, and  ${var#pattern}, which tests if $var
begins with pattern and if so deletes the match and returns the rest
(single hash for shortest match, double for longest) or ${var%pattern},
(same thing for the end).

Untested/unfinished(?) quick hack solution (I took your bait =8^):

echo "-- "
quote=${quotes[$RANDOM_NUMBER]}
# set wrapat as desired
wrapat=72
length=${#quote}
while [ $length -gt $wrapat ]; do
        # raw split, not on space
        line=${quote:0:$wrapat}
        # delete last space +
        line=${line% *}
        echo $line
        # subtract line from input quote
        quote=${quote#$line}
        # recalculate length
        length=${#quote}
done
echo $quote
echo "Homepage - www.wever.org" 
echo "Sesam Search Engine - www.sesam.no"

As I said, that's untested, but even if I bugged it, the code should be
clear enough with the comments and close enough to working to hack into
shape yourself, now that I gave you a start.

Note that you have two post-quote lines, so if the quote is long enough to
wrap into more than two lines, you'll violate max sig length netiquette
and get a warning from pan.  You could try doubling up the post-quote
lines as I did (tho it isn't needed with the sig I use for this list/group)
with my pre-quote lines to shorten the non-quote sig to a single line,
thus allowing three lines wrapped quotes. The lines total only 58 chars if
I counted correctly, so you have a bit of flexibility in spacing or other
separation, while still keeping the combined line <72-80 chars.

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman





reply via email to

[Prev in Thread] Current Thread [Next in Thread]