Permalink
Browse files

Merge pull request #14 from eregon/zsh_completion

Improve ZSH completion
  • Loading branch information...
2 parents ff04e2e + 70202b7 commit 74940d9972ed5ac1f1e652aa8128a2ee8ddb79dc @jneen committed Apr 8, 2012
Showing with 49 additions and 46 deletions.
  1. +3 −1 README.md
  2. +0 −1 bin/ry
  3. +46 −44 lib/ry.zsh_completion
View
@@ -10,7 +10,7 @@ cd ry
PREFIX=$HOME/.local make install
```
-and add the following lines to your bashrc:
+and add the following lines to your bashrc (or zshrc):
``` bash
# If you're using the default ~/.local prefix,
@@ -27,6 +27,8 @@ export PATH="$RY_PREFIX/lib/ry/current/bin:$PATH"
. "$RY_PREFIX/lib/ry.bash_completion"
```
+For ZSH completion, see [this](https://github.com/jayferd/ry/blob/master/lib/ry.zsh_completion).
+
## Usage
Ry is a bit different from [other][rvm] [version][rbenv] [managers][nvm]. The major design goal of ry is to be explicit, unobtrusive, and easy to query. In the vein of the [n][] package manager for node, there are no subshells, and the only thing it needs to add to your environment is a single entry to your `$PATH` (also tab completion if you like). For example, here's how you create a new installation:
View
@@ -83,7 +83,6 @@ 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
}
View
@@ -1,46 +1,48 @@
-_ry() {
- local -a rubies
- if (( CURRENT > 2 )); then
- shift words
- (( CURRENT-- ))
- subcmd="$words[1]"
+#compdef ry
- 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
-}
+# ry ZSH completion function
+# Symlink (or copy) this file in your $fpath (like /usr/share/zsh/site-functions)
+# and name it _ry: ln -s path/to/this/file _ry
-compdef _ry ry
+local -a rubies
+if (( CURRENT > 2 )); then
+ shift words
+ (( CURRENT-- ))
+ local 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

0 comments on commit 74940d9

Please sign in to comment.