diff options
author | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-16 18:49:26 +0900 |
---|---|---|
committer | Jari Vetoniemi <jari.vetoniemi@indooratlas.com> | 2020-03-30 00:39:06 +0900 |
commit | fcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch) | |
tree | 64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/misc/rb_optparse.zsh |
Fresh start
Diffstat (limited to 'jni/ruby/misc/rb_optparse.zsh')
-rwxr-xr-x | jni/ruby/misc/rb_optparse.zsh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/jni/ruby/misc/rb_optparse.zsh b/jni/ruby/misc/rb_optparse.zsh new file mode 100755 index 0000000..d53170c --- /dev/null +++ b/jni/ruby/misc/rb_optparse.zsh @@ -0,0 +1,38 @@ +#!/bin/zsh +# Completion for zsh: +# (based on <http://d.hatena.ne.jp/rubikitch/20071002/zshcomplete>) +# +# (1) install this file. +# mkdir -p ~/.zsh.d +# cp rb_optparse.zsh ~/.zsh.d/rb_optparse.zsh +# +# (2) load the script, and add a directory to fpath before compinit. +# echo '. ~/.zsh.d/rb_optparse.zsh' >> ~/.zshrc +# echo 'fpath=(~/.zsh.d/Completion $fpath)' >> ~/.zshrc +# echo 'autoload -U compinit; compinit' >> ~/.zshrc +# +# (3) restart zsh. +# +# (4) geneate completion files once. +# 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}" + $1 "--*-completion-zsh=${1:t}" >! "${ZSH_COMPLETION_DIR-$HOME/.zsh.d/Completion}/$cmpl" + if [[ $(type -w "$cmpl") == "${cmpl}: function" ]]; then + unfunction "$cmpl" + autoload -U "$cmpl" + else + compinit "$cmpl" + fi +} + +compdef _command generate-complete-function/ruby/optparse + +for cmd in "$@"; do + generate-complete-function/ruby/optparse "$cmd" +done |