]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
src/bin/diffman, diffman.1: Add program and its manual page
authorAlejandro Colomar <alx@kernel.org>
Mon, 25 Nov 2024 11:36:08 +0000 (12:36 +0100)
committerAlejandro Colomar <alx@kernel.org>
Mon, 25 Nov 2024 15:05:56 +0000 (16:05 +0100)
This program diffs manual pages.  It's useful for reviewing changes to a
manual page:

$ diffman membarrier ./man2/membarrier.2 | less -R;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
man/man1/diffman.1 [new file with mode: 0644]
src/bin/diffman [new file with mode: 0755]

diff --git a/man/man1/diffman.1 b/man/man1/diffman.1
new file mode 100644 (file)
index 0000000..1c27f58
--- /dev/null
@@ -0,0 +1,38 @@
+.\" Copyright 2024, Alejandro Colomar <alx@kernel.org>
+.\"
+.\" SPDX-License-Identifier: Linux-man-pages-copyleft
+.\"
+.TH diffman 1 (date) "Linux man-pages (unreleased)"
+.SH NAME
+diffman
+\-
+compare formatted manual pages line by line
+.SH SYNOPSIS
+.SY diffman
+.I page1
+.I page2
+.YS
+.SH DESCRIPTION
+The
+.B diffman
+command
+formats two manual pages,
+and then runs
+.BR diff (1)
+on the formatted outputs.
+.P
+The pages are specified with the same syntax that
+.BR man (1)
+accepts.
+.P
+The output is suitable for piping to
+.IR less\~\-R .
+.SH EXAMPLES
+.EX
+.RB $\~ "diffman membarrier man2/membarrier.2 | less \-R" ;
+$
+.EE
+.SH SEE ALSO
+.BR diff (1),
+.BR man (1),
+.BR less (1)
diff --git a/src/bin/diffman b/src/bin/diffman
new file mode 100755 (executable)
index 0000000..56f6741
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Copyright 2024, Alejandro Colomar <alx@kernel.org>
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+set -Eeuo pipefail;
+shopt -s lastpipe;
+
+err()
+{
+       >&2 echo "$(basename "$0"): error: $*";
+       exit 1;
+}
+
+if test $# -ne 2; then
+       err "Expected two arguments.";
+fi;
+
+p1="$(man -w "$1")";
+p2="$(man -w "$2")";
+
+printf '%s\n' "$1.XXXXXX" \
+| sed 's,.*/,,' \
+| xargs mktemp -t \
+| read -r t1;
+
+printf '%s\n' "$2.XXXXXX" \
+| sed 's,.*/,,' \
+| xargs mktemp -t \
+| read -r t2;
+
+groff -man -Tutf8 <"$p1" >"$t1";
+groff -man -Tutf8 <"$p2" >"$t2";
+
+diff -u "$t1" "$t2";