Skip to content

Instantly share code, notes, and snippets.

@kazuph
Last active December 15, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuph/5301397 to your computer and use it in GitHub Desktop.
Save kazuph/5301397 to your computer and use it in GitHub Desktop.
plenvのzsh補完をするためのScript。zshrcへ追加で使える。
_plenv() {
# cmdsという変数を定義
local -a cmds
# カーソルが現在何番目のコマンドを入力しようとしてるのかがCURRENTに入ってる
# すでにplenvと打っているはずなので補完は2コマンド目から
# 3番目以降のコマンドを入力しようとしているときにはelseへ行く
if (( CURRENT == 2 ));then
compadd init rehash exec which version help global local install list versions list_modules install_cpanm available migrate_modules
elif [ $words[CURRENT-1] = 'local' -o $words[CURRENT-1] = 'global' -o $words[CURRENT-1] = 'migrate_modules' -o $words[CURRENT-2] = 'migrate_modules' ];then
# $wordsという配列に入力したコマンドが入っているのでそれを使ってパターンマッチ
# 現在インストールされているPerlをパースして変換候補に
compadd `plenv list | sed -e 's/\*//g' -e 's/ //g'`
fi
return 1;
}
# plenvというコマンドに関数_plenvを関連付け
compdef _plenv plenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment