macho (767 bytes)
1 #!/bin/sh 2 # Pick a man page with fzf (apropos list, man preview) and open it. 3 # Usage: macho [-s section] [keyword...] 4 5 export FZF_DEFAULT_OPTS=' 6 --height=30% 7 --layout=reverse 8 --prompt="Manual: " 9 --preview="man {1} {2} 2>/dev/null"' 10 11 while getopts ":s:" opt; do 12 case $opt in 13 s ) SECTION=$OPTARG;; 14 \?) echo "Invalid option: -$OPTARG" >&2; exit 1;; 15 : ) echo "Option -$OPTARG requires an argument" >&2; exit 1;; 16 esac 17 done 18 shift $((OPTIND - 1)) 19 [ $# -gt 0 ] || set -- . 20 21 # "name (1) - desc" (man-db) or "name(1) - desc" (mandoc) -> "1 name" 22 manual=$(apropos ${SECTION:+-s "$SECTION"} "$@" | \ 23 sed -E 's/^([^ ,(]+)[^(]*\(([^,)]+).*/\2 \1/' | \ 24 sort | \ 25 fzf) 26 27 [ -z "$manual" ] && exit 0 28 man "${manual%% *}" "${manual##* }"