2022-08-28 20:36:34 +00:00
|
|
|
|
#!/bin/sh -e
|
2023-09-18 15:41:53 +00:00
|
|
|
|
# open info-page, man-page or command with help flag
|
2022-01-05 16:53:06 +00:00
|
|
|
|
# depends: unbuffer
|
|
|
|
|
# optdepends: highlight(dotfiles)
|
2022-08-04 21:53:53 +00:00
|
|
|
|
# TODO show tldr page
|
2023-09-18 15:41:53 +00:00
|
|
|
|
# TODO extract help in standard format from scripts
|
2021-09-16 12:18:26 +00:00
|
|
|
|
paginate="${PAGER:-less} +Gg"
|
2022-12-13 12:25:04 +00:00
|
|
|
|
case "$1" in
|
|
|
|
|
(-d) browse=1; shift;;
|
|
|
|
|
(-v) set -o xtrace; shift;;
|
2023-04-06 14:21:36 +00:00
|
|
|
|
("") echo "Provide an object to get help on or check out the following options:
|
2023-03-13 14:36:09 +00:00
|
|
|
|
tldr
|
|
|
|
|
info
|
|
|
|
|
man
|
2023-06-16 08:47:24 +00:00
|
|
|
|
quickref; test-colors; arg-test / arg-notify"; exit 2;;
|
2022-12-13 12:25:04 +00:00
|
|
|
|
esac
|
2022-07-15 11:33:29 +00:00
|
|
|
|
|
|
|
|
|
showinfo() {
|
|
|
|
|
which info >/dev/null 2>&1 &&
|
2022-07-15 11:43:37 +00:00
|
|
|
|
case $EDITOR in
|
2022-08-30 09:52:55 +00:00
|
|
|
|
(*emacs*) info "$@" -w | grep -v "manpages" | grep -q . && $EDITOR --eval "(progn (info \"$1\") (if \"$2\" (Info-index \"$2\")) (delete-other-windows))";;
|
2022-07-15 11:43:37 +00:00
|
|
|
|
(*vim) info "$@" -w | grep -q . && $EDITOR -R -M -c "Info $1" +only;;
|
2022-07-15 11:33:29 +00:00
|
|
|
|
(*) info -f "$1" $(test "$2" && echo "--index-search=$2") 2>/dev/null;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-11 11:06:43 +00:00
|
|
|
|
cmd="$1"
|
|
|
|
|
case "$cmd" in
|
2024-06-28 19:34:05 +00:00
|
|
|
|
(fwupdmgr|hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff|qpdf|ninja|qobuz-dl|beet)
|
2023-11-04 18:08:39 +00:00
|
|
|
|
unbuffer "$@" --help | sed 's|^[^ ].*:|[1m\0[22m|' | $paginate;;
|
2024-02-20 18:54:51 +00:00
|
|
|
|
(sqlcmd) sqlcmd -?;;
|
|
|
|
|
(exa) "$0" eza;;
|
2023-09-11 23:16:35 +00:00
|
|
|
|
(caddy|stretchly|go|flutter)
|
2022-05-11 11:06:43 +00:00
|
|
|
|
shift
|
|
|
|
|
"$cmd" help "$@" | $paginate;;
|
2023-09-18 15:41:53 +00:00
|
|
|
|
(doom|sgpt) "$@" --help;; # Paginates itself
|
2023-11-04 18:08:39 +00:00
|
|
|
|
(rsgain) "$@" custom --help;;
|
2023-07-27 15:16:41 +00:00
|
|
|
|
(spectre|plantuml|java) unbuffer "$@" -help | $paginate;;
|
2023-11-04 18:08:39 +00:00
|
|
|
|
(mpw) "$@" -h 2>&1 | $paginate;;
|
2022-08-28 20:36:34 +00:00
|
|
|
|
(rails) { "$@" -H && "$@" --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-08-28 20:36:34 +00:00
|
|
|
|
# Show manpage with tweaks
|
2023-09-11 23:16:35 +00:00
|
|
|
|
(fossil)
|
|
|
|
|
# TODO view fossil ui in terminal
|
|
|
|
|
if test $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")"
|
|
|
|
|
then fossil ui --page=doc/trunk/www/permutedindex.html "$repo"
|
|
|
|
|
else shift; fossil help "$@"
|
|
|
|
|
fi;;
|
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-}";;
|
2022-08-28 20:36:34 +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
|
|
|
|
|
showinfo zsh $(test "$last" != zsh && echo "$last") ||
|
2022-12-13 12:25:04 +00:00
|
|
|
|
LESS="$LESS$(test "$last" != zsh && echo "+/^ *$last *\\[")" man zshall;;
|
|
|
|
|
(emacs) man emacs;;
|
2022-09-19 21:46:05 +00:00
|
|
|
|
(*) showinfo "$@" || man "$@" || return=$?
|
2022-10-04 07:24:23 +00:00
|
|
|
|
if test "${return:-0}" -gt 0 && which "$cmd" >/dev/null
|
2022-09-19 21:46:05 +00:00
|
|
|
|
then { unbuffer "$@" --help || { test $? == 1 && "$@" -help; } || { test $? == 1 && "$@" -h; }; } 2>&1 | $paginate
|
2022-08-11 12:15:24 +00:00
|
|
|
|
return=$?
|
2022-02-10 14:59:41 +00:00
|
|
|
|
fi;;
|
2021-07-02 16:33:30 +00:00
|
|
|
|
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
|
2022-12-13 12:25:04 +00:00
|
|
|
|
len() { echo "$1" | wc -c; }
|
|
|
|
|
shortest() {
|
|
|
|
|
read shortest
|
|
|
|
|
while read in
|
|
|
|
|
do test $(len $shortest) -gt $(len $in) && shortest=$in
|
|
|
|
|
done
|
|
|
|
|
echo $shortest
|
|
|
|
|
}
|
|
|
|
|
file="$(find $docs -name index.html | shortest | grep . || find $docs -name $1*.html | shortest)"
|
|
|
|
|
|
2021-12-08 10:37:18 +00:00
|
|
|
|
if test -z "$browse"
|
2022-12-13 12:25:04 +00:00
|
|
|
|
then echo "Find more in file://${file:-docs}"
|
|
|
|
|
else firefox "file://$file"
|
2021-12-08 10:37:18 +00:00
|
|
|
|
fi
|
2021-09-29 16:38:57 +00:00
|
|
|
|
fi
|
2022-08-11 12:15:24 +00:00
|
|
|
|
exit $return
|