]> arthur.barton.de Git - pdfman.git/commitdiff
Suppress errors of the "man --version" command main
authorAlexander Barton <alex@barton.de>
Mon, 27 May 2024 19:28:24 +0000 (21:28 +0200)
committerAlexander Barton <alex@barton.de>
Mon, 27 May 2024 19:28:24 +0000 (21:28 +0200)
The man(1) command on macOS does not support any version output at
all, for example.

README.md
pdfman

index f40f599b7cdb1437201edd7a25891fdff15abce0..ad80a869300fc176b7df3f33dfd9ef53f2c01b8b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -2,7 +2,8 @@
 
 `pdfman` converts UNIX manual pages to PDF documents using Ghostscript's
 `ps2pdf`(1) or Apple's `pstopdf`(1) command (included in macOS up to version 13
-"Ventura") and displays them by calling `open`(1) on the resulting PDF file.
+"Ventura") and displays them by calling `xdg-open`(1) or `open`(1) on the
+resulting PDF file.
 This enhances the useability of the manual pages quite a bit, because you now
 can make use of your preferred PDF file viewer and all of its functionality.
 
@@ -14,7 +15,7 @@ invocations for the same topic.
 The `pdfman` script makes use of the following tools, which need to be available
 on the local system in the default search `$PATH`:
 
-- `open`(1)
+- `xdg-open`(1) _or_ `open`(1).
 - Either `ps2pdf`(1) of the Ghostscript suite _or_ `pstopdf`(1) which was
   included in Apple macOS up to version 13 "Ventura".
 
diff --git a/pdfman b/pdfman
index e68d4405e8ef4085e4bee7dc74d7e6561ccba97a..8ded8eda1150af8f45550d013fbf3a5d8dff101c 100755 (executable)
--- a/pdfman
+++ b/pdfman
@@ -22,23 +22,33 @@ while [[ $# -gt 0 ]]; do
                        # Enable verbose mode.
                        VERBOSE="-p"
                        ;;
+               "-F")
+                       # Force creating a PDF!
+                       FORCE="-F"
+                       ;;
                "-T")
                        # Force using man(1)!
                        shift
                        man "$@"
                        exit $?
                        ;;
-               "--help")
-                       echo "Usage: pdfman [-v] [-T] [<section>] <topic> ..." >&2
-                       echo "       pdfman <man(1) options> <arguments> ..." >&2
-                       echo "       pdfman {--help|--version>}" >&2
+               "--help"|"-h")
+                       echo "Usage:" >&2
+                       echo " $0 [-v] [-F] [<section>] <topic> ..." >&2
+                       echo " $0 -T [<section>] <topic> ..." >&2
+                       echo " $0 <man(1) options> <arguments> ..." >&2
+                       echo " $0 {-h|--help|--version>}" >&2
+                       echo >&2
+                       echo "  -F   Force PDF mode, even when not running on an interactive terminal"
+                       echo "  -T   Always use the man(1) command."
+                       echo "  -v   Enable verbose status messages." >&2
                        echo >&2
-                       man --help
+                       man -h >&2
                        exit 2
                        ;;
                "--version")
                        echo "pdfman, version 1" >&2
-                       man --version
+                       man --version 2>/dev/null
                        exit 2
                        ;;
                -*)
@@ -69,13 +79,19 @@ if [[ -z "$1" ]]; then
        exit $?
 fi
 
-# Make sure there is a terminal available ...
-if [[ ! -t 1 ]]; then
+# Fall back to the man(1) command when "force mode" is not active and no
+# terminal is connected to stdout:
+if [[ -z "$FORCE" ]] && [[ ! -t 1 ]]; then
        man "$@"
        exit $?
 fi
-# Make sure required tools are available ...
-if ! command -v open >/dev/null; then
+
+# Detect "opener" to use ...
+if command -v xdg-open >/dev/null; then
+       open_command=xdg-open
+elif command -v open >/dev/null; then
+       open_command=open
+else
        man "$@"
        exit $?
 fi
@@ -89,7 +105,8 @@ else
        man "$@"
        exit $?
 fi
-[[ -n "$VERBOSE" ]] && echo "Using ${ps_to_pdf_function#*_}(1) ..."
+
+[[ -n "$VERBOSE" ]] && echo "Using ${ps_to_pdf_function#*_}(1) and ${open_command}(1) ..."
 
 # Try to move old cache directory ...
 if [[ -d "$HOME/.pdfman" && ! -d "$CACHE" ]]; then
@@ -129,5 +146,5 @@ man -w "$@" | while read -r MANFILE; do
        fi
 
        [[ -n "$VERBOSE" ]] && echo "Opening \"$PDF\" ..."
-       open "$PDF"
+       $open_command "$PDF"
 done