Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zsh completion #13

Merged
merged 1 commit into from Apr 4, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -7,3 +7,4 @@ install:
install -d $(PREFIX)/bin $(PREFIX)/lib
install -C -m 0755 ./bin/ry $(PREFIX)/bin/ry
install -C -m 0644 ./lib/ry.bash_completion $(PREFIX)/lib/ry.bash_completion
install -C -m 0644 ./lib/ry.zsh_completion $(PREFIX)/lib/ry.zsh_completion
1 change: 1 addition & 0 deletions bin/ry
Expand Up @@ -83,6 +83,7 @@ ry::setup() {
cat <<sh
export PATH="$(ry fullpath "$@")";
if [ -n "\$BASH_VERSION" ]; then . "$RY_PREFIX/lib/ry.bash_completion"; fi
if [ -n "\$ZSH_VERSION" ]; then . "$RY_PREFIX/lib/ry.zsh_completion"; fi
sh
}

Expand Down
46 changes: 46 additions & 0 deletions lib/ry.zsh_completion
@@ -0,0 +1,46 @@
_ry() {
local -a rubies
if (( CURRENT > 2 )); then
shift words
(( CURRENT-- ))
subcmd="$words[1]"

case $subcmd in
setup|use|remove|rm|exec|binpath|fullpath)
rubies=($(_call_program rubies ry ls))
;;
install)
if (( $+commands[ruby-build] )); then
rubies=($(_call_program rubies ruby-build --definitions))
fi
;;
*)
rubies=()
;;
esac
_describe rubies rubies
else
local -a commands
# usage is not listed so "use" completes directly
commands=(
version:'show ry version'
help:'show the help'
current:'show the current ruby name'
setup:'setup ry (with an optional ruby as an argument)'
ls:'output the installed rubies'
rubies:'output the installed rubies, and highlight the current one'
use:'use the given ruby'
install:'install the given ruby-build recipe'
remove:'remove the given rubies'
rm:'remove the given rubies'
exec:'execute a command in the context of each comma-separated ruby'
binpath:'print the bin directory for the given ruby'
fullpath:'print a modified version of $PATH that exclusively includes the given ruby'
)
rubies=($(_call_program rubies ry ls))
_describe commands commands
_describe rubies rubies
fi
}

compdef _ry ry