Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add zsh completion #13

Merged
merged 1 commit into from

2 participants

Benoit Daloze Jeanine Adkisson
Benoit Daloze
Collaborator

Hello,

This my try to implement zsh completion for ry.
It's the first time I write a zsh completion script, but it works well and seems clean.

  • It's probably worth mentioning in the README that ry setup should be called in .zshrc, after compinit.
  • Another solution, more idiomatic for zsh, is to let the user create a symlink in his $fpath and make the completion an autoloadable function.

I still need to make my mind about that.

See #9

P.S.: Just installed ry yesterday and very happy since. (I just did not expect ry setup with an argument to disallow ry use afterwards)

Benoit Daloze
Collaborator

Also, I noticed exec, binpath and fullpath are not present in the bash completion. I guess the first just waits to be added but are the others intently left out (because they are considered internal API or such)?

Jeanine Adkisson
Owner

Wonderful, thank you!

That's a good point about ry setup vs ry use. Perhaps use should be named differently, since it changes the global symlink, where ry setup puts a different binpath on your $PATH.

Jeanine Adkisson jneen merged commit ff04e2e into from
Jeanine Adkisson jneen referenced this pull request
Closed

implement completion for zsh #9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2012
  1. Benoit Daloze

    add zsh completion

    eregon authored
This page is out of date. Refresh to see the latest.
Showing with 48 additions and 0 deletions.
  1. +1 −0  Makefile
  2. +1 −0  bin/ry
  3. +46 −0 lib/ry.zsh_completion
1  Makefile
View
@@ -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  bin/ry
View
@@ -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
}
46 lib/ry.zsh_completion
View
@@ -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
Something went wrong with that request. Please try again.