2010-11-19 15:07:09 +03:00
|
|
|
#!/bin/zsh
|
|
|
|
# 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.
|
2010-12-12 14:40:29 +03:00
|
|
|
# echo '. ~/.zsh.d/rb_optparse.zsh' >> ~/.zshrc
|
2010-12-12 15:06:36 +03:00
|
|
|
# echo 'fpath=(~/.zsh.d/Completion $fpath)' >> ~/.zshrc
|
|
|
|
# echo 'autoload -U compinit; compinit' >> ~/.zshrc
|
2010-11-19 15:07:09 +03:00
|
|
|
#
|
2010-12-12 14:40:29 +03:00
|
|
|
# (3) restart zsh.
|
|
|
|
#
|
|
|
|
# (4) geneate 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
|
|
|
|
unfunction "$cmpl"
|
2010-12-06 13:01:53 +03:00
|
|
|
autoload -U "$cmpl"
|
2010-11-19 15:07:09 +03:00
|
|
|
else
|
|
|
|
compinit "$cmpl"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
for cmd in "$@"; do
|
|
|
|
generate-complete-function/ruby/optparse "$cmd"
|
|
|
|
done
|