dotfiles/.local/bin/scripts/help

55 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-05-11 11:06:43 +00:00
#!/bin/sh
2021-09-29 16:38:57 +00:00
# open info-page, man-page or command help
2022-01-05 16:53:06 +00:00
# depends: unbuffer
# optdepends: highlight(dotfiles)
paginate="${PAGER:-less} +Gg"
2021-09-29 16:38:57 +00:00
test "$1" = "-d" && browse=1 && shift
2022-05-11 11:06:43 +00:00
cmd="$1"
case "$cmd" in
2021-12-08 10:37:18 +00:00
(zsh|zmv) # https://unix.stackexchange.com/questions/19290/zmv-for-zsh-dry-runs-and-man-pages
for last; do true; done
# need to install zsh-doc package for info pages
info $(test "$last" != zsh && echo "--index-search=$last") zsh ||
2021-12-08 10:37:18 +00:00
LESS="$LESS +/^ *$last *\\[" man zshall;;
(gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker) unbuffer "$@" --help | $paginate;;
(caddy|stretchly|go|fossil) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit
# TODO view fossil ui in terminal
2022-05-11 11:06:43 +00:00
shift
"$cmd" help "$@" | $paginate;;
2022-07-06 06:59:22 +00:00
(doom) "$@" --help;;
(rails) { "$@" -H && "$@" --help; } | $paginate;;
2022-01-05 16:53:06 +00:00
(plantuml) unbuffer "$@" -help | $paginate;;
2022-05-11 11:06:43 +00:00
(vlc) shift && unbuffer vlc --full-help "$@" | $paginate;;
(kdeconnect*) shift && kdeconnect-cli --help-all "$@" | $paginate;;
2022-02-10 14:59:41 +00:00
(pandoc) man pandoc; highlight "Extensions" && pandoc --list-extensions | paste -s -d' ';;
2022-05-11 11:06:43 +00:00
(swaymsg) test $# -gt 1 && shift && man sway "$@" || man swaymsg;;
2022-01-07 18:15:25 +00:00
(swaymsg-*) man sway "${1#swaymsg-}";;
(*) {
which info >/dev/null 2>&1 &&
case $EDITOR in
(*vim) info "$@" -w | grep -q . && $EDITOR -R -M -c "Info $*" +only;;
(*) info -f "$@" 2>/dev/null;;
esac ||
man "$@"
} ||
2022-05-11 11:06:43 +00:00
if which "$cmd" >/dev/null
2022-04-12 17:31:46 +00:00
then { "$@" --help || { test $? == 1 && "$@" -help; } || { test $? == 1 && "$@" -h; }; } 2>&1 | $paginate
2022-02-10 14:59:41 +00:00
fi;;
esac
2022-05-11 11:06:43 +00:00
docs="/usr/share/doc/$cmd"
2021-09-29 16:38:57 +00:00
if test -d "$docs"; then
2021-12-08 10:37:18 +00:00
if test -z "$browse"
then echo "Find more in $docs"
else
2022-05-11 11:06:43 +00:00
len() { echo "$1" | wc -c; }
2021-12-08 10:37:18 +00:00
shortest() {
read shortest
while read in
do test $(len $shortest) -gt $(len $in) && shortest=$in
done
echo $shortest
}
firefox "file://$(find $docs -name index.html | shortest | grep . || find $docs -name $1*.html | shortest)"
fi
2021-09-29 16:38:57 +00:00
fi