public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] dog - man's best friend.
@ 2012-02-23 20:42 Alan Mackenzie
  2012-02-23 20:52 ` [gentoo-user] " Nikos Chantziaras
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Alan Mackenzie @ 2012-02-23 20:42 UTC (permalink / raw
  To: gentoo-user

Hi, Gentoo!

I've finally been pushed over the edge.  I simply can't stand it any
longer.  The "it" in this case is viewing a file or process output and
either: (a) using less, and have it take just 10 screen lines; (b) using
cat etc., and have the interesting part scroll away.

To solve this dilemma, I've written dog, a short script that will splat
lines to the screen if they're few enough, invoke less otherwise.  I've
set the threshold between the two cases at 60 lines.  If your screen is
a different size, change the two obvious bits.

Enjoy!

dog:
#########################################################################

#!/bin/bash
export IFS=""
lin=0
while [ $lin -lt 60 ] && read ; do
    buf[$lin]=$REPLY
    lin=$((lin + 1))
done

if [ $lin -ge 60 ] ; then
    (
        for (( i = 0 ; i < 60 ; i++ )) ; do
            echo ${buf[$i]}
        done
        while read ; do
            echo $REPLY
        done
    ) | less
else
    for (( i = 0 ; i < $lin ; i++ )) ; do
        echo ${buf[$i]}
    done
fi

#########################################################################

-- 
Alan Mackenzie (Nuremberg, Germany).



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-02-25 21:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-23 20:42 [gentoo-user] dog - man's best friend Alan Mackenzie
2012-02-23 20:52 ` [gentoo-user] " Nikos Chantziaras
2012-02-23 20:58 ` [gentoo-user] " Neil Bothwick
2012-02-23 21:28 ` Kevin Monceaux
2012-02-23 23:24   ` [gentoo-user] " Harry Putnam
2012-02-23 23:40     ` Willie WY Wong
2012-02-25 21:19       ` Harry Putnam
2012-02-24  0:02     ` Paul Hartman
2012-02-25 21:22       ` Harry Putnam
2012-02-23 21:32 ` [gentoo-user] " Paul Hartman
2012-02-23 21:37   ` Paul Hartman
2012-02-23 21:58     ` Alan Mackenzie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox