Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gentoo-user] dog - man's best friend.

2 views
Skip to first unread message

Alan Mackenzie

unread,
Feb 23, 2012, 3:50:02 PM2/23/12
to
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).

Nikos Chantziaras

unread,
Feb 23, 2012, 4:00:03 PM2/23/12
to
On 23/02/12 22:42, Alan Mackenzie wrote:
> I've
> set the threshold between the two cases at 60 lines. If your screen is
> a different size, change the two obvious bits.

You can use the $LINES env variable to get the height of the current
terminal. Another way to get them is with the "tput" command. "tput
lines" and "tput cols" print the amount of lines and columns on stdout.

Neil Bothwick

unread,
Feb 23, 2012, 4:10:01 PM2/23/12
to
On Thu, 23 Feb 2012 20:42:00 +0000, Alan Mackenzie wrote:

If the subject is true, why does your dog have no man page?

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

% eix -e dog
[I] sys-apps/dog
Available versions: 1.7-r4{tbz2}
Installed versions: 1.7-r4{tbz2}(15:54:25 20/12/11)
Homepage: http://packages.gentoo.org/package/sys-apps/dog
Description: Dog is better than cat

--
Neil Bothwick

Top Oxymorons Number 27: Military Intelligence
signature.asc

Paul Hartman

unread,
Feb 23, 2012, 4:40:02 PM2/23/12
to
On Thu, Feb 23, 2012 at 2:42 PM, Alan Mackenzie <a...@muc.de> wrote:
> 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.

You should just alias less to "less -E", it does exactly what you invented. :)

Kevin Monceaux

unread,
Feb 23, 2012, 4:40:02 PM2/23/12
to
On Thu, Feb 23, 2012 at 08:42:00PM +0000, Alan Mackenzie wrote:

> (a) using less, and have it take just 10 screen lines; (b) using cat etc.,
> and have the interesting part scroll away.

(c) use less -F and less will automatically exit if the entire file can fit
on one screen. One can export LESS='-F' to have less always do the above.



--

Kevin
http://www.RawFedDogs.net
http://www.WacoAgilityGroup.org
Bruceville, TX

What's the definition of a legacy system? One that works!
Errare humanum est, ignoscere caninum.

Paul Hartman

unread,
Feb 23, 2012, 4:50:02 PM2/23/12
to
Oops, typo, I meant -F not -E. :)

Alan Mackenzie

unread,
Feb 23, 2012, 5:10:01 PM2/23/12
to
Hi, Paul.
Well, that's one way of discovering new features in familiar software.
;-)

Thanks!

Harry Putnam

unread,
Feb 23, 2012, 6:30:01 PM2/23/12
to
Kevin Monceaux <Ke...@RawFedDogs.net> writes:

> On Thu, Feb 23, 2012 at 08:42:00PM +0000, Alan Mackenzie wrote:
>
>> (a) using less, and have it take just 10 screen lines; (b) using cat etc.,
>> and have the interesting part scroll away.
>
> (c) use less -F and less will automatically exit if the entire file can fit
> on one screen. One can export LESS='-F' to have less always do the above.

Maybe I'm seeing behavior that is not supposed to happen, but if I say
echo '## ONE LINE' > test

And then say less -F test

I do not get to see the one line. I don't think that's what Alan
was looking for is it?

Willie WY Wong

unread,
Feb 23, 2012, 6:40:01 PM2/23/12
to
On Thu, Feb 23, 2012 at 06:24:29PM -0500, Penguin Lover Harry Putnam squawked:
That is not supposed to happen. Is that in a X terminal or on the text
console?

If you `less test` and quit, does the content of the test file stay on
screen or does it get cleared (I bet the former)? Try `less -XF test`
in that case, and see if it helps.

W
--
Data aequatione quotcunque fluentes quantitae involvente fluxiones invenire
et vice versa ~~~ I. Newton

Paul Hartman

unread,
Feb 23, 2012, 7:10:02 PM2/23/12
to
It is caused by "alternate screen" handling in your terminal emulator.
You can disable alternate screen in your terminal (if possible), or
remove the smcup and rmcup directives from your termcap file.

As a test, you can try this:

export TERM=vt220
less -F test

it should display the one line file.

Or you can use the -X option of less like Willie said which inhibits
less from using the alternate screen.

But I think it may still be a bug in less, because when it's not in
"pager mode" we shouldn't be using the alternate screen anyway. Taking
a look at the bug list on the less website, I don't see anything.
Might be worth submitting.

Harry Putnam

unread,
Feb 25, 2012, 4:30:02 PM2/25/12
to
Willie WY Wong <won...@member.ams.org> writes:

> On Thu, Feb 23, 2012 at 06:24:29PM -0500, Penguin Lover Harry Putnam squawked:
>> > On Thu, Feb 23, 2012 at 08:42:00PM +0000, Alan Mackenzie wrote:
>> >
>> >> (a) using less, and have it take just 10 screen lines; (b) using cat etc.,
>> >> and have the interesting part scroll away.
>> >
>> > (c) use less -F and less will automatically exit if the entire file can fit
>> > on one screen. One can export LESS='-F' to have less always do the above.
>>
>> Maybe I'm seeing behavior that is not supposed to happen, but if I say
>> echo '## ONE LINE' > test
>>
>> And then say less -F test
>>
>> I do not get to see the one line. I don't think that's what Alan
>> was looking for is it?
>
> That is not supposed to happen. Is that in a X terminal or on the text
> console?

Real xterm in kde desktop (not konsole or any of the wannabes, just
plain xterm)

xterm -version
XTerm(276)

> If you `less test` and quit, does the content of the test file stay on
> screen or does it get cleared (I bet the former)? Try `less -XF test`
> in that case, and see if it helps.

(I guess you meant `latter'... not `former' eh?)

Here it is cleared... and yup `less -XF test' does as expected. less
doesn't start but the one line is shown.

(For the record: I have never used any of that and have no intention
or need to. I just saw the thread, tried it myself and saw what I
posted.)

Thanks for the input.

Oh, and this is all happening on a Debian (Testing) machine.

Harry Putnam

unread,
Feb 25, 2012, 4:30:02 PM2/25/12
to
Paul Hartman <paul.hart...@gmail.com> writes:

[...]

>>> (c) use less -F and less will automatically exit if the entire file can fit
>>> on one screen.  One can export LESS='-F' to have less always do the above.
>>
>> Maybe I'm seeing behavior that is not supposed to happen, but if I say
>> echo '## ONE LINE' > test
>>
>> And then say less -F test
>>
>> I do not get to see the one line.   I don't think that's what Alan
>> was looking for is it?
>
> It is caused by "alternate screen" handling in your terminal emulator.
> You can disable alternate screen in your terminal (if possible), or
> remove the smcup and rmcup directives from your termcap file.
>
> As a test, you can try this:
>
> export TERM=vt220
> less -F test
>
> it should display the one line file.
>
> Or you can use the -X option of less like Willie said which inhibits
> less from using the alternate screen.

OK, thanks for the input... good information. I'm not really likely
to use that command much or ever... but good to know.

I guess you see the same behavior I reported? That is, that a one
line file is not displayed with `less -F file' ?
0 new messages