2010-11-19 07:07:09 -05:00
|
|
|
#!/bin/zsh
|
|
|
|
# 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.
|
2010-12-12 06:40:29 -05:00
|
|
|
# echo '. ~/.zsh.d/rb_optparse.zsh' >> ~/.zshrc
|
2010-12-12 07:06:36 -05:00
|
|
|
# echo 'fpath=(~/.zsh.d/Completion $fpath)' >> ~/.zshrc
|
|
|
|
# echo 'autoload -U compinit; compinit' >> ~/.zshrc
|
2010-11-19 07:07:09 -05:00
|
|
|
#
|
2010-12-12 06:40:29 -05:00
|
|
|
# (3) restart zsh.
|
|
|
|
#
|
|
|
|
# (4) geneate 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
|
|
|
|
unfunction "$cmpl"
|
2010-12-06 05:01:53 -05:00
|
|
|
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
|