dotfiles-remastered/.local/share/scripts/macho.sh

25 lines
633 B
Bash
Raw Normal View History

2020-07-12 15:40:33 +00:00
#!/usr/bin/env sh
export FZF_DEFAULT_OPTS='
--prompt="Manual: "
2023-10-17 22:34:53 +00:00
--preview="echo {1} | sed -E \"s/^\((.+)\)/\1/\" | xargs -I{S} man -Pcat {S} {2} | bat -l man -p --color=always 2>/dev/null"'
2020-07-12 15:40:33 +00:00
while getopts ":s:" opt; do
case $opt in
s ) SECTION=$OPTARG; shift; shift;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
: ) echo "Option -$OPTARG requires an argument" >&2; exit 1;;
esac
done
manual=$(apropos -s ${SECTION:-''} ${@:-.} | \
grep -v -E '^.+ \(0\)' |\
awk '{print $2 " " $1}' | \
sort | \
fzf | \
sed -E 's/^\((.+)\)/\1/')
[ -z "$manual" ] && exit 0
man $manual