From: martin f. krafft Date: Fri, 23 Jan 2009 05:34:53 +0000 (+1100) Subject: Merge commit 'refs/top-bases/fixes/independent-help' into fixes/independent-help X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=6e92736dd815e29c3715362970380f5e9a759a11;p=topgit.git Merge commit 'refs/top-bases/fixes/independent-help' into fixes/independent-help Conflicts: tg.sh --- 6e92736dd815e29c3715362970380f5e9a759a11 diff --cc tg.sh index 258f8ce,7c6c09f..6282250 --- a/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@" ] ||