-> 07 { 10 / 03 }
zsh で optparse.rb を使った ruby スクリプトのオプション補完を自動生成する の手順
おお素晴らしい、のだけど適用方法がよく解らなかったのと、まんまだとエラーになるので手順メモ。なお自分は completeion ディレクトリを $HOME/.zsh/completion/ にしてるので適宜読み替えてね。
completion ディレクトリをあらかじめ作る
作って、かつファイルが何か無いとエラーるよ。
mkdir ~/.zsh/completion touch ~/.zsh/completion/example
.zshrc に追記とか変更とか
compinit あたりを変更
fpath=($HOME/.zsh/completion $fpath)
autoload -U $HOME/.zsh/completion/*(:t)
autoload -U compinit
compinit
generate-complete-function/ruby/optparse () {
ruby -r $HOME/bin/zshcomplete $1 > $HOME/.zsh/completion/_`basename $1`
reload-complete-functions
}
reload-complete-functions() {
local f
f=($HOME/.zsh/completion/*(.))
unfunction $f:t 2> /dev/null
autoload -U $f:t
}
zshcomplete.txt を ~/bin/zshcomplete.rb に保存
タイトルママ。
を落として .rb に変更して保存(別に変更しなくても良いけど)。またダブルクオーテーションが入ってるoptionだとエラーになるのでエスケープしておく。本家に取り込んでもらいました。ありがとうございます。
準備完了
これで zsh を立ち上げ直せば(source ~/.zshrc でもいいのかな)使えるように。rascut でやってみると
generate-complete-function/ruby/optparse =rascut
$ rascut -[tab] --bind-address -b -- server bind address(default 0.0.0.0) --compile-config -c -- mxmlc compile config ex:) --compile-config="-benchmark -strict=true" --fcsh-cmd -- fcsh command path --help -- show this message --interval -i -- interval time(min) --log -l -- showing flashlog.txt --mapping -m -- server mapping path :example) -m "../assets=assets" -m "../images/=img" --no-file-observe -- don't observing files --observe-ext -- observe ext ex:) --observe-ext="as3,actionscript3,css,mxml" --observe-files -I -- observe files and directories path --plugin -- load plugin(s) --port -p -- server port(default: 3001) --server -s -- start autoreload webserver --server-handler -- set server hander :example) --server-handler=webrick --template -t -- server use template file --verbose -v -- detail messages
やべー超簡単にできた。感動。
コメント
トラックバック - http://subtech.g.hatena.ne.jp/secondlife/20071003