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