chiark / gitweb /
Merge commit 'refs/top-bases/fixes/independent-help' into fixes/independent-help
authormartin f. krafft <madduck@debian.org>
Fri, 23 Jan 2009 05:34:53 +0000 (16:34 +1100)
committermartin f. krafft <madduck@debian.org>
Fri, 23 Jan 2009 05:34:53 +0000 (16:34 +1100)
Conflicts:
tg.sh

1  2 
tg.sh

diff --cc tg.sh
index 258f8ce4fd6e2e145300bf85c81f869786222e7b,7c6c09f2eaa709933dc4631495c7b440556882db..6282250ee0d4e63fcca583a52cd47fc39aefc53e
--- 1/tg.sh
--- 2/tg.sh
+++ b/tg.sh
@@@ -235,29 -265,45 +265,68 @@@ do_help(
        fi
  }
  
 +# Check whether we are supposed to output the help message
 +should_do_help()
 +{
 +      # we are being sourced for utility functions, never run help
 +      [ -z "$tg__include" ] || return 1
 +
 +      local prev
 +      while [ -n "$1" ]; do
 +              case "$1" in
 +              help|--help|-h)
 +                      shift
 +                      echo "${1:-$prev}"
 +                      return 0
 +              esac
 +              prev="$1"
 +              shift
 +      done
 +
 +      # run help when there was no previous topic, meaning that there where
 +      # no arguments at all
 +      test -z "$prev"
 +}
 +
+ ## Pager stuff
+ # isatty FD
+ isatty()
+ {
+       test -t $1
+ }
+ # setup_pager
+ # Spawn pager process and redirect the rest of our output to it
+ setup_pager()
+ {
+       isatty 1 || return 0
+       # TG_PAGER = GIT_PAGER | PAGER | less
+       # NOTE: GIT_PAGER='' is significant
+       TG_PAGER=${GIT_PAGER-${PAGER-less}}
+       [ -z "$TG_PAGER"  -o  "$TG_PAGER" = "cat" ]  && return 0
+       # now spawn pager
+       export LESS=${LESS:-FRSX}       # as in pager.c:pager_preexec()
+       _pager_fifo_dir="$(mktemp -t -d tg-pager-fifo.XXXXXX)"
+       _pager_fifo="$_pager_fifo_dir/0"
+       mkfifo -m 600 "$_pager_fifo"
+       "$TG_PAGER" < "$_pager_fifo" &
+       exec > "$_pager_fifo"           # dup2(pager_fifo.in, 1)
+       # this is needed so e.g. `git diff` will still colorize it's output if
+       # requested in ~/.gitconfig with color.diff=auto
+       export GIT_PAGER_IN_USE=1
+       # atexit(close(1); wait pager)
+       trap "exec >&-; rm \"$_pager_fifo\"; rmdir \"$_pager_fifo_dir\"; wait" EXIT
+ }
  ## Startup
  
  [ -d "@cmddir@" ] ||