[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-user
Subject:    [gentoo-user] dog - man's best friend.
From:       Alan Mackenzie <acm () muc ! de>
Date:       2012-02-23 20:42:00
Message-ID: 20120223204200.GE2834 () acm ! acm
[Download RAW message or body]

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).

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic