]> source.dussan.org Git - jgit.git/commitdiff
jgit.sh: Implement pager support 90/3590/1
authorShawn O. Pearce <spearce@spearce.org>
Sun, 29 May 2011 20:05:03 +0000 (13:05 -0700)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 31 May 2011 15:58:45 +0000 (08:58 -0700)
If the command is either `diff` or `log`, there is often a lot of
lines of output. Run these commands through $GIT_PAGER, $PAGER, or
`less` in order to make it easier to browse the output on a terminal.

Change-Id: I18b87ea4acf404b94788f2ac2101812bd13e6a0f
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit.pgm/jgit.sh

index e6a2119ef1669399d946fdc09c61aa2d0629ba5a..9ff59d6122dfb070967e91c12c935f6fda4303f1 100644 (file)
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+cmd=
+for a in "$@"
+do
+       case "$a" in
+       -*) continue ;;
+       *)  cmd=$a; break; ;;
+       esac
+done
+
+use_pager=
+case "$cmd" in
+diff)     use_pager=1 ;;
+log)      use_pager=1 ;;
+esac
 
 this_script=`which "$0" 2>/dev/null`
 [ $? -gt 0 -a -f "$0" ] && this_script="$0"
@@ -58,7 +72,7 @@ CYGWIN*)
        cp=`cygpath --windows --mixed --path "$cp"`
        ;;
 Darwin)
-       if test -e /System/Library/Frameworks/JavaVM.framework
+       if [ -e /System/Library/Frameworks/JavaVM.framework ]
        then
                java_args='
                        -Dcom.apple.mrj.application.apple.menu.about.name=JGit
@@ -74,10 +88,25 @@ CLASSPATH="$cp"
 export CLASSPATH
 
 java=java
-if test -n "$JAVA_HOME"
+if [ -n "$JAVA_HOME" ]
 then
        java="$JAVA_HOME/bin/java"
 fi
 
-exec "$java" $java_args org.eclipse.jgit.pgm.Main "$@"
-exit 1
+if [ -n "$use_pager" ]
+then
+       use_pager=${GIT_PAGER:-${PAGER:-less}}
+       [ cat = "$use_pager" ] && use_pager=
+fi
+
+if [ -n "$use_pager" ]
+then
+       LESS=${LESS:-FSRX}
+       export LESS
+
+       "$java" $java_args org.eclipse.jgit.pgm.Main "$@" | $use_pager
+       exit
+else
+  exec "$java" $java_args org.eclipse.jgit.pgm.Main "$@"
+  exit 1
+fi