Created
November 2, 2022 09:12
-
-
Save ernstki/fb49d948ee9cb7676764ce074090c431 to your computer and use it in GitHub Desktop.
Fetch man pages from manpages.debian.org and typeset in the terminal (for macOS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## | |
## lman - fetch GNU/Linux man pages from manpages.debian.org | |
## | |
## Author: Kevin Ernst | |
## Date: 1 November 2022 | |
## License: Unlicense - https://unlicense.org/#the-unlicense | |
## | |
# can override any of these by setting LMAN_* in the environment | |
MAXWIDTH=${LMAN_MAXWIDTH:-100} | |
ENCODING=${LMAN_ENCODING:-utf8} | |
LANG=${LMAN_LANG:-en} | |
BASEURL=${LMAN_BASEURL:-'https://manpages.debian.org/stable'} | |
_lman() { | |
local termwidth=$(tput cols) | |
local width=$(( termwidth < MAXWIDTH ? termwidth : maxwidth )) | |
local margin=$(( (termwidth - width) / 2 )) | |
local pad=$(printf "%${margin}s") | |
local manpage=${1:?What manual page do you want?} | |
# center MAXWIDTH columns within the terminal | |
curl -sL "$BASEURL/$manpage.$LANG.gz" \ | |
| groff -man -T$ENCODING -rLL=${width}n \ | |
| sed "s/^/$pad/" \ | |
| less | |
} | |
# run the function if the script is being executed | |
[[ $0 == $BASH_SOURCE ]] && _lman "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why would you ever want to do this? Maybe you're a sysadmin, writing scripts that need to run on both macOS/BSD and GNU/Linux.
It's useful when you want to know what are the lowest common denominator options supported by, say,
find
orgrep
on Mac/BSD and Linux.See also