1 |
Hi, Gentoo! |
2 |
|
3 |
I've finally been pushed over the edge. I simply can't stand it any |
4 |
longer. The "it" in this case is viewing a file or process output and |
5 |
either: (a) using less, and have it take just 10 screen lines; (b) using |
6 |
cat etc., and have the interesting part scroll away. |
7 |
|
8 |
To solve this dilemma, I've written dog, a short script that will splat |
9 |
lines to the screen if they're few enough, invoke less otherwise. I've |
10 |
set the threshold between the two cases at 60 lines. If your screen is |
11 |
a different size, change the two obvious bits. |
12 |
|
13 |
Enjoy! |
14 |
|
15 |
dog: |
16 |
######################################################################### |
17 |
|
18 |
#!/bin/bash |
19 |
export IFS="" |
20 |
lin=0 |
21 |
while [ $lin -lt 60 ] && read ; do |
22 |
buf[$lin]=$REPLY |
23 |
lin=$((lin + 1)) |
24 |
done |
25 |
|
26 |
if [ $lin -ge 60 ] ; then |
27 |
( |
28 |
for (( i = 0 ; i < 60 ; i++ )) ; do |
29 |
echo ${buf[$i]} |
30 |
done |
31 |
while read ; do |
32 |
echo $REPLY |
33 |
done |
34 |
) | less |
35 |
else |
36 |
for (( i = 0 ; i < $lin ; i++ )) ; do |
37 |
echo ${buf[$i]} |
38 |
done |
39 |
fi |
40 |
|
41 |
######################################################################### |
42 |
|
43 |
-- |
44 |
Alan Mackenzie (Nuremberg, Germany). |