Created
May 17, 2021 15:43
-
-
Save loreb/999c5f7e5b4316d3d0d49da08a215f8f to your computer and use it in GitHub Desktop.
Script to check if it's worth it to compress man pages
This file contains 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
#! /bin/sh | |
# https://paludis.exherbo.org/faq/misfunctionality.html#wgetresume | |
# true<<TIL => shellcheck usefully complains... | |
til() { : ; } | |
til<<TIL | |
No Automatic Documentation Compression | |
Non-Problem: Paludis doesn't compress documentation or man pages with gzip/bzip/whatever. | |
Rationale: The space savings on an average system are very small, to non-existent for most filesystems. Most documentation and man pages are only about one block in size, so compression won't gain you anything except for wasted CPU cycles. | |
TIL | |
# Absolutely true on my void install! (2K uncompressed) | |
# Instead on debian I get instead compressed=>2042, uncompressed median 4810 bytes! | |
# (assuming filesystems use blocks >= 4KB) | |
shellcheck "$0" | |
# Disable warnings about use of egrep and fgrep; also $(($N + 1)) | |
# shellcheck disable=SC2196,SC2197,SC2004 | |
# The rationale is: | |
# $ a='1+1' | |
# $ echo $(($a * 5)) # becomes 1+1*5 | |
# 6 | |
# $ echo $((a * 5)) # evaluates as (1+1)*5 | |
# The colon (':') is to put unknown options in $OPTARG. | |
# TODO does anyone use bzip2, xz, ...? | |
measureCompressedManpages() { | |
unset -f useraw cook | |
eval 'useraw() { iscompressed "$1" ; }' | |
eval 'cook() { cat "$1" | gzip ; }' | |
} | |
measureVanillaManpages() { | |
unset -f useraw cook | |
eval 'useraw() { if iscompressed "$1" ; then false; else true; fi ; }' | |
eval 'cook() { cat "$1" | gzip -d || ls -ld "$1" ; }' | |
} | |
measureVanillaManpages | |
# Use _getopts_, "getopt" is deprecated (it has long options & shuffling) | |
while getopts ":cd" Option ; do | |
case $Option in | |
(c) measureCompressedManpages ;; | |
(d) measureVanillaManpages ;; | |
(*) echo "unknown option $OPTARG" >&2; exit 100;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
iscompressed() { | |
case "$1" in | |
(*.gz|*.bz2) true ;; | |
(*) false ;; | |
esac | |
} | |
if test -t 1 ; then | |
echo >&2 "Usage: $0 [-dc] [DIR...] | ministat -A" | |
exit 100 | |
fi | |
test $# -gt 0 || set -- /usr/man /usr/share/man /usr/local/share/man | |
for dir in "$@" ; do | |
cd "$dir" || continue | |
for i in m*/*.* ; do | |
test -e "$i" || continue # broken symlinks happen | |
test -d "$i" && continue # internationalization | |
if useraw "$i" ; then | |
wc -c <"$i" | |
else | |
cook "$i" | wc -c | |
fi | |
done | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment