aboutsummaryrefslogtreecommitdiff
path: root/bin/han
diff options
context:
space:
mode:
Diffstat (limited to 'bin/han')
-rwxr-xr-xbin/han22
1 files changed, 11 insertions, 11 deletions
diff --git a/bin/han b/bin/han
index 7c495d2b..0f081890 100755
--- a/bin/han
+++ b/bin/han
@@ -3,31 +3,31 @@
self=han
# Give up completely if no BASH_VERSINFO (<2.0)
-if ! [ -n "$BASH_VERSINFO" ] ; then
- exit
-fi
+[ -n "$BASH_VERSINFO" ] || exit
# Figure out the options with which we can call help; Bash >=4.0 has an -m
-# option which prints the help output in a man-page like format.
+# option which prints the help output in a man-page like format
declare -a helpopts
if ((BASH_VERSINFO[0] >= 4)) ; then
helpopts=(-m)
fi
-# Create a temporary file and set up a trap to get rid of it.
-tmpdir=$(mktemp -dt "$self".XXXXXX) || exit
+# Create a temporary directory with name in $td, and a trap to remove it when
+# the script exits
+td=
cleanup() {
- rm -fr -- "$tmpdir"
+ [[ -n "$td" ]] && rm -fr -- "$td"
}
trap cleanup EXIT
+td=$(mktd "$self") || exit
# If we have exactly one argument and a call to the help builtin with that
-# argument succeeds, display its output with `pager -s`.
+# argument succeeds, display its output with `pager -s`
if (($# == 1)) &&
- help "${helpopts[@]}" "$1" >"$tmpdir"/"$1".help 2>/dev/null ; then
- (cd -- "$tmpdir" && pager -s -- "$1".help)
+ help "${helpopts[@]}" "$1" >"$td"/"$1".help 2>/dev/null ; then
+ (cd -- "$td" && "$PAGER" -s -- "$1".help)
-# Otherwise, just pass all the arguments to man(1).
+# Otherwise, just pass all the arguments to man(1)
else
man "$@"
fi