Last active
July 28, 2019 04:51
-
-
Save cmplstofB/da3b33938320b0227229f771cd12d6e3 to your computer and use it in GitHub Desktop.
vimhelp.sh---Vimの手引きをコマンドラインから閲覧する (Vimのコマンドそれ自体を除いてPOSIX準拠)。
This file contains hidden or 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 | |
__METADATA__='@prefix : <http://purl.org/net/ns/doas#>. <> a :ShellScript; | |
:一行説明 "Vimの手引きをコマンドラインから閲覧する。"; | |
:作成日 "2019-07-27"; | |
:公開版 [:版 "0.1.2"; :作成日 "2019-07-28"]; | |
:作成者 "cmplstofB"; | |
:権利 "ⓒ 2019 cmplstofB"; | |
:ライセンス <http://www.wtfpl.net/txt/copying/>; | |
:依存関係 "vim(1)".' | |
vimhelp() { set -- "$1" | |
for vimcand in $vimcands; do | |
if command -v "$vimcand" > '/dev/null'; then | |
VIMCMD="$vimcand" | |
break | |
fi | |
done | |
$VIMCMD -f -c "help $1 | only" | |
} | |
die() { set -- "$1" ${2:-$?} | |
printf '%s: [\033[1;31mERROR\033[22;39m] %s\n' "${0##*/}" "$1" | |
exit $(($2?$2:1)) | |
} >&2 | |
print_help() { set -- | |
printf '\033[36mUsage\033[39m: '; { | |
printf '\033[1m%s\033[22m [\033[3m%s\033[23m] [\033[3m%s\033[23m]\n' \ | |
"${0##*/}" '-g|--gui' '<word>' | |
} | |
printf '\033[36mOperand\033[39m\n'; { | |
printf '\t\033[1m%s\033[22m\t%s\n' 'word' 'Help word.' | |
} | expand -t '2,22' | |
printf '\033[36mOptions\033[39m\n'; { | |
printf '\t\033[1m%s\033[22m\t%s\n' '-g --gui' 'Run in GUI mode.' | |
printf '\t\033[1m%s\033[22m\t%s\n' '-h --help' 'Print this help.' | |
printf '\t\033[1m%s\033[22m\t%s\n' '--version' 'Print version.' | |
} | expand -t '2,22' | |
} | |
print_version() { set -- | |
printf '%s %d.%d.%d\n\n' "${0##*/}" 0 1 2 | |
printf '© %d %s\n' '2019' 'cmplstofB' | |
printf 'License: %s\n' 'WTFPL' | |
} | |
main() { | |
set -o errexit | |
set -o nounset | |
umask 0022 | |
export PATH="$(command -p getconf PATH):$PATH" | |
vimcands='vim vim81 vim80 vim8 | |
vim74 vim73 vim72 vim71 vim70 vim7 | |
vim6 vi' | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
'-h'|'--help') | |
print_help | |
exit $? | |
;; | |
'--version') | |
print_version | |
exit $? | |
;; | |
'-g'|'--gui') | |
vimcands='gvim gvim81 gvim80 gvim8 | |
gvim74 gvim73 gvim72 gvim71 gvim70 gvim7 | |
gvim6 '"$vimcands" | |
shift | |
;; | |
*) | |
vimhelp "$1" | |
break | |
;; | |
esac | |
done | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment