git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [cogito] paged output for cg-diff
@ 2005-05-20  9:05 Michal Rokos
  2005-05-20 12:53 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Rokos @ 2005-05-20  9:05 UTC (permalink / raw)
  To: git

Hello,

I'm a bit curious what is going on in development so I'm using cg-diff
often. Usually I pipe it to the less. So for me it would be very nice
when cg-diff behaves as cg-log that pipes output to pager.

So I changed cg-diff to do so.

New function PAGER() determines whether output is terminal and uses
PAGER in that case.

Do you like it?

 Michal

Signed-off-by: Michal Rokos <michal@rokos.info>

Index: cg-Xlib
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-Xlib  (mode:100755)
+++ uncommitted/cg-Xlib  (mode:100755)
@@ -91,3 +91,12 @@
 
 export BROKEN_MKTEMP=1
 del=$($(which mktemp) -t 2>/dev/null) && { rm $del; export BROKEN_MKTEMP=; }
+
+PAGER () {
+ if [ -t 1 ]; then
+  ${PAGER:-less} ${PAGER_FLAGS:--R}
+ else
+  cat
+ fi
+}
+
Index: cg-diff
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-diff  (mode:100755)
+++ uncommitted/cg-diff  (mode:100755)
@@ -71,7 +71,7 @@
  # FIXME: Update ret based on what did we match. And take "$@"
  # to account after all.
  ret=
- git-diff-cache -r -z $tree | xargs -0 ${COGITO_LIB}cg-Xdiffdo "$tree" uncommitted "$filter"
+ git-diff-cache -r -z $tree | xargs -0 ${COGITO_LIB}cg-Xdiffdo "$tree" uncommitted "$filter" | PAGER
 
  [ "$filter" ] && rm $filter
 
@@ -85,7 +85,7 @@
 
 [ "$id1" = "$id2" ] && die "trying to diff $id1 against itself"
 
-git-diff-tree -r -z $id1 $id2 | xargs -0 ${COGITO_LIB}cg-Xdiffdo $id1 $id2 "$filter"
+git-diff-tree -r -z $id1 $id2 | xargs -0 ${COGITO_LIB}cg-Xdiffdo $id1 $id2 "$filter" | PAGER
 
 [ "$filter" ] && rm $filter
 exit 0
Index: cg-log
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-log  (mode:100755)
+++ uncommitted/cg-log  (mode:100755)
@@ -181,4 +181,4 @@
 
   done
  echo
-done | ${PAGER:-less} ${PAGER_FLAGS:--R}
+done | PAGER

-- 
Michal Rokos

NextSoft s.r.o.
Vyskočilova 1/1410
140 21 Praha 4
tel: +420 267 224 311
fax: +420 267 224 307
mobil: +420 736 646 591
e-mail: michal.rokos@nextsoft.cz

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cogito] paged output for cg-diff
  2005-05-20  9:05 [cogito] paged output for cg-diff Michal Rokos
@ 2005-05-20 12:53 ` Junio C Hamano
  2005-05-20 14:55   ` Thomas Glanzmann
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2005-05-20 12:53 UTC (permalink / raw)
  To: Michal Rokos; +Cc: git

>>>>> "MR" == Michal Rokos <michal.rokos@nextsoft.cz> writes:

MR> I'm a bit curious what is going on in development so I'm using cg-diff
MR> often. Usually I pipe it to the less. So for me it would be very nice
MR> when cg-diff behaves as cg-log that pipes output to pager.

I think that is a sensible thing to do.  But doesn't "less"
already do this part without being told?

MR> +PAGER () {
MR> + if [ -t 1 ]; then
MR> +  ${PAGER:-less} ${PAGER_FLAGS:--R}
MR> + else
MR> +  cat
MR> + fi
MR> +}



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cogito] paged output for cg-diff
@ 2005-05-20 13:17 Michal Rokos
  2005-05-20 13:50 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Michal Rokos @ 2005-05-20 13:17 UTC (permalink / raw)
  To: git

Hello,

Junio is right, following is sufficent. Tested with 'more' too.

 Michal

PS: I'm off the list, so please CC me.

Signed-off-by: Michal Rokos <michal@rokos.info>
Idea-from: Junio C Hamano <junkio@cox.net>

Index: cg-Xlib
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-Xlib  (mode:100755)
+++ uncommitted/cg-Xlib  (mode:100755)
@@ -91,3 +91,8 @@

 export BROKEN_MKTEMP=1
 del=$($(which mktemp) -t 2>/dev/null) && { rm $del; export BROKEN_MKTEMP=; }
+
+PAGER () {
+       ${PAGER:-less} ${PAGER_FLAGS:--R}
+}
+
Index: cg-diff
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-diff  (mode:100755)
+++ uncommitted/cg-diff  (mode:100755)
@@ -71,7 +71,7 @@
        # FIXME: Update ret based on what did we match. And take "$@"
        # to account after all.
        ret=
-       git-diff-cache -r -z $tree | xargs -0 ${COGITO_LIB}cg-Xdiffdo "$tree" uncommitted "$filter"
+       git-diff-cache -r -z $tree | xargs -0 ${COGITO_LIB}cg-Xdiffdo "$tree" uncommitted "$filter" | PAGER

        [ "$filter" ] && rm $filter

@@ -85,7 +85,7 @@

 [ "$id1" = "$id2" ] && die "trying to diff $id1 against itself"

-git-diff-tree -r -z $id1 $id2 | xargs -0 ${COGITO_LIB}cg-Xdiffdo $id1 $id2 "$filter"
+git-diff-tree -r -z $id1 $id2 | xargs -0 ${COGITO_LIB}cg-Xdiffdo $id1 $id2 "$filter" | PAGER

 [ "$filter" ] && rm $filter
 exit 0
Index: cg-log
===================================================================
--- ca5fef50fb68a3afbb35e1a48ac622f7a964f021/cg-log  (mode:100755)
+++ uncommitted/cg-log  (mode:100755)
@@ -181,4 +181,4 @@

                done
        echo
-done | ${PAGER:-less} ${PAGER_FLAGS:--R}
+done | PAGER

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cogito] paged output for cg-diff
  2005-05-20 13:17 Michal Rokos
@ 2005-05-20 13:50 ` Junio C Hamano
  2005-05-29 14:01   ` Petr Baudis
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2005-05-20 13:50 UTC (permalink / raw)
  To: Michal Rokos; +Cc: git

>>>>> "MR" == Michal Rokos <michal@rokos.info> writes:

MR> Junio is right, following is sufficent. Tested with 'more' too.
MR> Idea-from: Junio C Hamano <junkio@cox.net>

I appreciate the credit, but that is probably not needed in this
case, since this is quite commonly used pattern.  I've seen many
people do just this:

          command | ${PAGER:-less}

And if you think about it, you would realize that the above is
good enough, and probably is a lot better than what you are
doing.

Your PAGER shell function gives "-R" indiscriminately when
$PAGER_FLAGS is not set (or set to empty, which is even worse
because you are not giving the user to override this _bad_
choice) without even checking if the $PAGER is something that
understands "-R" (namely, "less").  I do not think users with
their PAGER set to "more" or "cat" (I do the latter when I am
working in Emacs) would appreciate that behaviour.

On the other hand, if your user is a "less" user, and if the
user wants it to honor ANSI "color" escape sequences, it would
be more helpful to the user if you educate/encourage the user to
have "LESS=R" in the environment and make that in effect
everywhere less is used not just in Cogito.  Giving that support
silently just in Cogito at the first thought may seem to be more
helpful but in reality it is not.

So I would suggest to use the above form without defining your
own PAGER shell function, and add a tip for "less" users to have
"LESS=R" in their environment somewhere in the documentation.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cogito] paged output for cg-diff
  2005-05-20 12:53 ` Junio C Hamano
@ 2005-05-20 14:55   ` Thomas Glanzmann
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Glanzmann @ 2005-05-20 14:55 UTC (permalink / raw)
  To: git

Hello,

> I think that is a sensible thing to do.  But doesn't "less"
> already do this part without being told?

yes, every pager does.

	Thomas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cogito] paged output for cg-diff
  2005-05-20 13:50 ` Junio C Hamano
@ 2005-05-29 14:01   ` Petr Baudis
  0 siblings, 0 replies; 6+ messages in thread
From: Petr Baudis @ 2005-05-29 14:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Michal Rokos, git

Dear diary, on Fri, May 20, 2005 at 03:50:57PM CEST, I got a letter
where Junio C Hamano <junkio@cox.net> told me that...
> On the other hand, if your user is a "less" user, and if the
> user wants it to honor ANSI "color" escape sequences, it would
> be more helpful to the user if you educate/encourage the user to
> have "LESS=R" in the environment and make that in effect
> everywhere less is used not just in Cogito.  Giving that support
> silently just in Cogito at the first thought may seem to be more
> helpful but in reality it is not.
> 
> So I would suggest to use the above form without defining your
> own PAGER shell function, and add a tip for "less" users to have
> "LESS=R" in their environment somewhere in the documentation.

Using the $LESS variable didn't occur to me and I like the idea. :-)
I think the most reasonable thing for Cogito will be to set LESS=R$LESS
if the user passed -c to the given command.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-29 13:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-20  9:05 [cogito] paged output for cg-diff Michal Rokos
2005-05-20 12:53 ` Junio C Hamano
2005-05-20 14:55   ` Thomas Glanzmann
  -- strict thread matches above, loose matches on Subject: below --
2005-05-20 13:17 Michal Rokos
2005-05-20 13:50 ` Junio C Hamano
2005-05-29 14:01   ` Petr Baudis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).