dman is now compatible with macOS/FreeBSD. Huge thanks to @stokito for helping upstream this patch!
curl https://salsa.debian.org/debian/debian-goodies/-/raw/master/dman?ref_type=heads > ~/.local/bin/dmandman is now compatible with macOS/FreeBSD. Huge thanks to @stokito for helping upstream this patch!
curl https://salsa.debian.org/debian/debian-goodies/-/raw/master/dman?ref_type=heads > ~/.local/bin/dman| #!/bin/sh | |
| set -e | |
| # dman - read man pages from manpages.debian.org | |
| # Patched for macOS by Alexander Pushkov <[email protected]> | |
| ############################################################################### | |
| # Copyright (C) 2008 Canonical Ltd. | |
| # | |
| # This code was originally written by Dustin Kirkland <[email protected]>, | |
| # based on a framework by Kees Cook <[email protected]>. | |
| # | |
| # It was later modified for Debian, for use in the debian-goodies package, | |
| # by Antoine Beaupré <[email protected]>, Axel Beckert <[email protected]> | |
| # and Javier Fernández-Sanguino <[email protected]> | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| # | |
| # On Debian-based systems, the complete text of the GNU General Public | |
| # License can be found in /usr/share/common-licenses/GPL-3 | |
| ############################################################################### | |
| # default to stable since we're not on an LSB compliant system | |
| DISTRIB_CODENAME=${DISTRIB_CODENAME:-stable} | |
| usage() | |
| { | |
| echo "Usage: $0 [ --release suite ] man-page <man-arguments>" | |
| } | |
| download_man(){ | |
| url=$1 | |
| file=$2 | |
| curl $CURLOPTS "$url" >"$file" 2>/dev/null | |
| if ! [ -s "$file" ] || | |
| egrep -q "<title>403.*Forbidden</title>" "$file" || | |
| egrep -q "<h1>Manpage not found</h1>" "$file" ; then | |
| return 1 | |
| fi | |
| return 0 | |
| } | |
| # Process command line options | |
| while true; do | |
| case "$1" in | |
| --release) | |
| DISTRIB_CODENAME="$2" | |
| shift 2 | |
| ;; | |
| --help) | |
| usage | |
| exit 0 | |
| ;; | |
| *) | |
| break | |
| ;; | |
| esac | |
| done | |
| PAGE=`echo "$@" | awk '{print $NF}'` | |
| MAN_ARGS=`echo "$@" | sed "s/\$PAGE$//"` | |
| # Sanity checks | |
| if [ ! -x "`which curl`" ] ; then | |
| echo "ERROR: $0 - cannot find curl - exiting" | |
| exit 1 | |
| fi | |
| if [ -z "$PAGE" ] ; then | |
| echo "ERROR: No manpage provided - exiting" | |
| usage | |
| exit 1 | |
| fi | |
| # PROGRAM OPTIONS | |
| CURLOPTS="-s -L" # -s for silent, -L to follow redirects | |
| # Mirror support of man's languages | |
| if [ ! -z "$LANG" ]; then | |
| LOCALE=$(echo $LANG | sed 's/_.*$//') | |
| LOCDOT=".$LOCALE" | |
| fi | |
| if [ ! -z "$LC_MESSAGES" ]; then | |
| LOCALE="$LC_MESSAGES" | |
| LOCDOT=".$LOCALE" | |
| fi | |
| if echo $LOCALE | grep -E -q "^(C|en)"; then | |
| LOCALE="" | |
| LOCDOT=".en" | |
| fi | |
| BASE_URL="https://dyn.manpages.debian.org" | |
| mandir=`mktemp -d dman.XXXXXX` | |
| trap "rm -rf $mandir" EXIT HUP INT QUIT TERM | |
| man="$mandir/$PAGE" | |
| TESTED_URLS="" | |
| # be careful not to add too many entries in this loop, as each hit can | |
| # take some time for the round-trip | |
| for URL in "$BASE_URL/$DISTRIB_CODENAME/$PAGE$LOCDOT.gz" \ | |
| "$BASE_URL/$DISTRIB_CODENAME/$PAGE.en.gz" \ | |
| "$BASE_URL/$DISTRIB_CODENAME/$PAGE.gz" \ | |
| "$BASE_URL/$PAGE$LOCDOT.gz" \ | |
| "$BASE_URL/$PAGE.en.gz" \ | |
| "$BASE_URL/$PAGE.gz" \ | |
| do | |
| if download_man $URL $man; then | |
| man $MAN_ARGS "$man" || true | |
| exit 0 | |
| fi | |
| # Continue in case of failure, take note of tested URL | |
| if [ -z "$TESTED_URLS" ] ; then | |
| TESTED_URLS="$URL" | |
| else | |
| TESTED_URLS="$TESTED_URLS, $URL" | |
| fi | |
| done | |
| echo "$0: not found. Tried: $TESTED_URLS" 1>&1 | |
| exit 1 |
Убрал -l в man $MAN_ARGS -l "$man" || true. На маке и *BSD -l не поддерживается, но если в аргументе есть слеш, он трактуется как путь к манпейджу (например, FreeBSD man(1), раздел Displaying Specific Manual Files).
Убрал --tmpdir у mktemp (тоже не поддерживается).
Не знаю, насколько имеет смысл добавлять эти изменения в goodies, особенно учитывая что для man нужно будет добавлять какую-то проверку, чтобы работало и на линуксе (где всё ещё нужен -l), и на маке.
(В debian-goodies ещё вот эти два патча есть, которых нет у меня — с ними должно быть всё ок, сейчас проверю и добавлю к себе.)
Спасибо за ответ. На Убунте ман работает тоже если просто путь указать. Ну и --tmpdir стрёмная затея.
Так что эти изменения можно смело пушить.
Если вам лень я могу сам пул реквест отправить.
Пока обедал проверил скрипт с мака жены и сделал ПР
https://salsa.debian.org/debian/debian-goodies/-/merge_requests/7
Тут объяснение зачем нужен --tmpdir
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=861611
Но есть простое решение просто использовать -t
@stokito 🔥, спасибо!
ПР вмерджили
https://salsa.debian.org/debian/debian-goodies/-/commit/d360ea94ba7956930c319c7afd961c371fa5336e
теперь вы контрибьютор в Дебиан :)
А что именно пришлось поменять чтобы заработало в маке? Я сравнил с версией из debian-goodies но не понял
https://salsa.debian.org/debian/debian-goodies/-/blob/master/dman?ref_type=heads
Не могли бы вы отправить изменения в этот дебиан гудис? Я думаю они будут не против.