# [cogito] paged output for cg-diff

3 messages from 2005-05-20 to 2005-05-20. Participants: Michal Rokos, Junio C Hamano, Thomas Glanzmann.
Thread: https://gitlist.dev/t/669

## Michal Rokos, 2005-05-20 09:05

Subject: [cogito] paged output for cg-diff
Message-ID: <200505201105.08711.michal.rokos@nextsoft.cz>
URL: https://gitlist.dev/e/200505201105.08711.michal.rokos%40nextsoft.cz

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

```

## Junio C Hamano, 2005-05-20 12:53

Subject: Re: [cogito] paged output for cg-diff
Message-ID: <7v64xevz15.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64xevz15.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <200505201105.08711.michal.rokos@nextsoft.cz>

```
>>>>> "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> +}



```

## Thomas Glanzmann, 2005-05-20 14:55

Subject: Re: [cogito] paged output for cg-diff
Message-ID: <20050520145546.GP8105@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20050520145546.GP8105%40cip.informatik.uni-erlangen.de
In-Reply-To: <7v64xevz15.fsf@assigned-by-dhcp.cox.net>

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

```
