Make tg help work in any directory
authorRobin Green <greenrd@greenrd.org>
Thu, 7 Mar 2013 21:28:11 +0000 (7 21:28 +0000)
committerRobin Green <greenrd@greenrd.org>
Thu, 7 Mar 2013 21:28:11 +0000 (7 21:28 +0000)
Signed-off-by: Robin Green <greenrd@greenrd.org>
tg.sh

diff --git a/tg.sh b/tg.sh
index 9082d88..24eee23 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -399,7 +399,7 @@ setup_pager()
        export LESS="${LESS:-FRSX}"     # as in pager.c:pager_preexec()
 
        # setup_pager should be called only once per command
-       pager_fifo="$tg_tmp_dir/pager"
+       pager_fifo="${tg_tmp_dir:-${HOME}}/.tg-pager"
        mkfifo -m 600 "$pager_fifo"
 
        "$TG_PAGER" < "$pager_fifo" &
@@ -411,7 +411,7 @@ setup_pager()
 
        # atexit(close(1); wait pager)
        # deliberately overwrites the global EXIT trap
-       trap "exec >&-; rm -rf \"$tg_tmp_dir\"; wait" EXIT
+       trap "exec >&-; rm -rf \"${tg_tmp_dir:-${HOME}/.tg-pager}\"; wait" EXIT
 }
 
 # get_temp NAME [-d]
@@ -429,19 +429,28 @@ get_temp()
 
 ## Initial setup
 
-set -e
-git_dir="$(git rev-parse --git-dir)"
-root_dir="$(git rev-parse --show-cdup)"; root_dir="${root_dir:-.}"
+cmd="$1"
+[ -z "$tg__include" ] || cmd="include" # ensure setup happens
+case "$cmd" in
+help|--help|-h)
+        :;;
+*)
+        if [ -n "$cmd" ]; then
+            set -e
+            git_dir="$(git rev-parse --git-dir)"
+            root_dir="$(git rev-parse --show-cdup)"; root_dir="${root_dir:-.}"
 # Make sure root_dir doesn't end with a trailing slash.
-root_dir="${root_dir%/}"
-base_remote="$(git config topgit.remote 2>/dev/null)" || :
-tg="tg"
+            root_dir="${root_dir%/}"
+            base_remote="$(git config topgit.remote 2>/dev/null)" || :
+            tg="tg"
 # make sure merging the .top* files will always behave sanely
-setup_ours
-setup_hook "pre-commit"
-# create global temporary directories, inside GIT_DIR
-tg_tmp_dir="$(mktemp -d "$git_dir/tg-tmp.XXXXXX")"
-trap "rm -rf \"$tg_tmp_dir\"" EXIT
+            setup_ours
+            setup_hook "pre-commit"
+            # create global temporary directories, inside GIT_DIR
+            tg_tmp_dir="$(mktemp -d "$git_dir/tg-tmp.XXXXXX")"
+            trap "rm -rf \"$tg_tmp_dir\"" EXIT
+        fi
+esac
 
 ## Dispatch
 
@@ -461,7 +470,6 @@ if [ "$1" = "-r" ]; then
        tg="$tg -r $base_remote"
 fi
 
-cmd="$1"
 [ -n "$cmd" ] || { do_help; exit 1; }
 shift