Suggestion: Pager only for long output

8 views
Skip to first unread message

Leszek Swirski

unread,
Oct 18, 2009, 6:39:27 AM10/18/09
to ack dev/users
Although ack's --pager="less -R" option is better than piping grep
into less, it's also more longer/more awkward to type (hyphens, quote
marks, etc.). So, I've got it permanently set in my .ackrc. However,
this results in awkward viewing of short and empty results. Would it
be possible to add a flag so that the pager is only used if the length
of the output exceeds the height of the terminal?

Andy Lester

unread,
Oct 18, 2009, 10:52:50 AM10/18/09
to ack-...@googlegroups.com

On Oct 18, 2009, at 5:39 AM, Leszek Swirski wrote:

> this results in awkward viewing of short and empty results. Would it
> be possible to add a flag so that the pager is only used if the length
> of the output exceeds the height of the terminal?


No, because we'd have to know how many results there are before we
started sending any output.

xoxo,
Andy

--
Andy Lester => an...@petdance.com => www.theworkinggeek.com => AIM:petdance


Packy Anderson

unread,
Oct 18, 2009, 11:29:09 AM10/18/09
to ack-...@googlegroups.com
Sure.  I use --pager="less -FRX".  F causes less to automatically exit if the entire file can be displayed on one screen, and X disables the termcap initialization and deinitialization sequences (on my systems, these sequences cause less to save the contents of the screen buffer when it starts and restore it when it exits, so I don't have anything from the less session on the screen when I'm done).

I thought this was the default for ack.  I know that I learned about these options from looking at ack's defaults.

-packy
--
Packy Anderson

Email:  PackyA...@gmail.com
GVoice: (646) 833-8832

Sitaram Chamarty

unread,
Oct 18, 2009, 12:08:28 PM10/18/09
to ack-...@googlegroups.com
On Sun, Oct 18, 2009 at 4:09 PM, Leszek Swirski
<leszek....@gmail.com> wrote:

> [snip] Would it


> be possible to add a flag so that the pager is only used if the length
> of the output exceeds the height of the terminal?

from man less:

-F or --quit-if-one-screen
Causes less to automatically exit if the entire file can
be displayed on the first screen.

Randall Hansen

unread,
Oct 18, 2009, 9:29:05 PM10/18/09
to ack-...@googlegroups.com
On Oct 18, 2009, at 7:52 AM, Andy Lester wrote:

> No, because we'd have to know how many results there are before we
> started sending any output.

So, we can already specify pager options. How 'bout an inline way to
toggle the pager on and off? We might also need a new env variable.
E.g.,

$ export ACK_USE_PAGER=false # the default
$ ack # do NOT use the pager
$ ack -p # use the pager defined by ACK_PAGER

$ export ACK_USE_PAGER=true
$ ack # use the pager
$ ack -p # use the pager

I don't know if this is a good idea or not, but I can't imagine
another way to solve this.

r

Andy Lester

unread,
Oct 18, 2009, 10:15:17 PM10/18/09
to ack-...@googlegroups.com

On Oct 18, 2009, at 8:29 PM, Randall Hansen wrote:

> I don't know if this is a good idea or not, but I can't imagine
> another way to solve this.

There's a --nopager option already.

Packy Anderson

unread,
Oct 18, 2009, 11:11:03 PM10/18/09
to ack-...@googlegroups.com
On Sun, Oct 18, 2009 at 9:29 PM, Randall Hansen <ran...@raan.net> wrote:
I don't know if this is a good idea or not, but I can't imagine
another way to solve this.

Why not, as Sitaram and I suggested, let less deal with the problem by specifying the -F command.

Andy, I could have sworn that "less -FRX" was ack's default pager at one point.  Am I imagining things?

Andy Lester

unread,
Oct 19, 2009, 12:18:27 AM10/19/09
to ack-...@googlegroups.com

On Oct 18, 2009, at 10:11 PM, Packy Anderson wrote:

> Andy, I could have sworn that "less -FRX" was ack's default pager at
> one point. Am I imagining things?

I don't think it ever was. I'm not much of a pager fan anyway.

xoa

Leszek Swirski

unread,
Oct 22, 2009, 6:16:26 AM10/22/09
to ack dev/users

On Oct 18, 4:29 pm, Packy Anderson <packyander...@gmail.com> wrote:
> Sure.  I use --pager="less -FRX".  F causes less to automatically exit if
> the entire file can be displayed on one screen, and X disables the termcap
> initialization and deinitialization sequences

Brilliant, for some reason it didn't occur to me to change the pager
parameters.

I was just using the pager as recommended by the help file. Maybe we
should change the recommended pager in the help from less -R to less -
FRX?

Andy Lester

unread,
Oct 22, 2009, 10:00:13 AM10/22/09
to ack-...@googlegroups.com

On Oct 22, 2009, at 5:16 AM, Leszek Swirski wrote:

> I was just using the pager as recommended by the help file. Maybe we
> should change the recommended pager in the help from less -R to less -
> FRX?


Patches welcome. It's all in github. (I guess then it should really
be "fork pull requests welcome")

Reply all
Reply to author
Forward
0 new messages