2021-03-29 09:36:16 +03:00
|
|
|
# -*- zsh -*-
|
|
|
|
#
|
2010-11-19 15:07:09 +03:00
|
|
|
# Completion for zsh:
|
|
|
|
# (based on <http://d.hatena.ne.jp/rubikitch/20071002/zshcomplete>)
|
|
|
|
#
|
2010-12-12 14:40:29 +03:00
|
|
|
# (1) install this file.
|
|
|
|
# mkdir -p ~/.zsh.d
|
|
|
|
# cp rb_optparse.zsh ~/.zsh.d/rb_optparse.zsh
|
2010-11-19 15:07:09 +03:00
|
|
|
#
|
2010-12-12 15:06:36 +03:00
|
|
|
# (2) load the script, and add a directory to fpath before compinit.
|
2020-10-12 12:47:00 +03:00
|
|
|
# echo '. ~/.zsh.d/rb_optparse.zsh' >> "${ZDOTDIR:-~}/.zshrc"
|
|
|
|
# echo 'fpath=(~/.zsh.d/Completion $fpath)' >> "${ZDOTDIR:-~}/.zshrc"
|
|
|
|
# echo 'autoload -U compinit; compinit' >> "${ZDOTDIR:-~}/.zshrc"
|
2010-11-19 15:07:09 +03:00
|
|
|
#
|
2010-12-12 14:40:29 +03:00
|
|
|
# (3) restart zsh.
|
|
|
|
#
|
2019-12-20 03:19:39 +03:00
|
|
|
# (4) generate completion files once.
|
2010-11-19 15:07:09 +03:00
|
|
|
# generate-complete-function/ruby/optparse COMMAND1
|
|
|
|
# generate-complete-function/ruby/optparse COMMAND2
|
|
|
|
#
|
|
|
|
|
|
|
|
generate-complete-function/ruby/optparse ()
|
|
|
|
{
|
|
|
|
local cmpl="_${1:t}"
|
|
|
|
mkdir -p "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}"
|
2010-12-12 14:40:29 +03:00
|
|
|
$1 "--*-completion-zsh=${1:t}" >! "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl"
|
2010-11-19 15:07:09 +03:00
|
|
|
if [[ $(type -w "$cmpl") == "${cmpl}: function" ]]; then
|
2021-03-18 00:24:10 +03:00
|
|
|
unfunction "$cmpl"
|
|
|
|
autoload -U "$cmpl"
|
2010-11-19 15:07:09 +03:00
|
|
|
else
|
|
|
|
compinit "$cmpl"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-12-27 02:30:38 +03:00
|
|
|
compdef _command generate-complete-function/ruby/optparse
|
|
|
|
|
2010-11-19 15:07:09 +03:00
|
|
|
for cmd in "$@"; do
|
|
|
|
generate-complete-function/ruby/optparse "$cmd"
|
|
|
|
done
|