FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Gentoo > Gentoo User

 
 
LinkBack Thread Tools
 
Old 02-23-2012, 07:42 PM
Alan Mackenzie
 
Default dog - man's best friend.

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).
 
Old 02-23-2012, 07:52 PM
Nikos Chantziaras
 
Default dog - man's best friend.

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.
 
Old 02-23-2012, 07:58 PM
Neil Bothwick
 
Default dog - man's best friend.

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
 
Old 02-23-2012, 08:28 PM
Kevin Monceaux
 
Default dog - man's best friend.

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.
 
Old 02-23-2012, 08:32 PM
Paul Hartman
 
Default dog - man's best friend.

On Thu, Feb 23, 2012 at 2:42 PM, Alan Mackenzie <acm@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.
 
Old 02-23-2012, 08:37 PM
Paul Hartman
 
Default dog - man's best friend.

On Thu, Feb 23, 2012 at 3:32 PM, Paul Hartman
<paul.hartman+gentoo@gmail.com> wrote:
> On Thu, Feb 23, 2012 at 2:42 PM, Alan Mackenzie <acm@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.

Oops, typo, I meant -F not -E.
 
Old 02-23-2012, 08:58 PM
Alan Mackenzie
 
Default dog - man's best friend.

Hi, Paul.

On Thu, Feb 23, 2012 at 03:37:34PM -0600, Paul Hartman wrote:
> On Thu, Feb 23, 2012 at 3:32 PM, Paul Hartman
> <paul.hartman+gentoo@gmail.com> wrote:
> > On Thu, Feb 23, 2012 at 2:42 PM, Alan Mackenzie <acm@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.

> Oops, typo, I meant -F not -E.

Well, that's one way of discovering new features in familiar software.
;-)

Thanks!

--
Alan Mackenzie (Nuremberg, Germany).
 
Old 02-23-2012, 10:24 PM
Harry Putnam
 
Default dog - man's best friend.

Kevin Monceaux <Kevin@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?
 
Old 02-23-2012, 10:40 PM
Willie WY Wong
 
Default dog - man's best friend.

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?

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
 
Old 02-23-2012, 11:02 PM
Paul Hartman
 
Default dog - man's best friend.

On Thu, Feb 23, 2012 at 5:24 PM, Harry Putnam <reader@newsguy.com> wrote:
> Kevin Monceaux <Kevin@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?

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.
 

Thread Tools




All times are GMT. The time now is 12:15 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org