Skip to content

Instantly share code, notes, and snippets.

@hauleth
Last active December 15, 2015 23:09
Show Gist options
  • Save hauleth/5337768 to your computer and use it in GitHub Desktop.
Save hauleth/5337768 to your computer and use it in GitHub Desktop.
My fish function file for `rbenv` (require `rbenv-whatis` plugin for all features) :) Happy hacking.
function rbenv_shell
set -l vers $argv[1]
switch "$vers"
case '--complete'
echo '--unset'
echo 'system'
command rbenv versions --bare
return
case '--unset'
set -e RBENV_VERSION
case ''
if [ -z "$RBENV_VERSION" ]
echo "rbenv: no shell-specific version configured" >&2
return 1
else
echo "$RBENV_VERSION"
return
end
case '*'
rbenv prefix "$vers" > /dev/null
set -gx RBENV_VERSION "$vers"
end
end
function rbenv_use
set -l ruby $argv[1]
if [ "$ruby" = "--complete" ]
echo system
exec rbenv versions --bare
end
switch (count $argv)
case 1
if [ "$ruby" = "default" ]
set ruby '--unset'
end
set command shell
case 2
switch $argv[2]
case '--global' '-g' '--default' '-d'
set command global
case '--shell' '-s'
set command shell
case '--local' '-l'
set command local
end
case '*'
echo "usage: rbenv use NAME [OPTION]" >&2
exit 1
end
set ruby (command rbenv whatis $ruby)
if [ "$command" = "shell" ]
rbenv_shell $ruby
else
rbenv_shell --unset; and command rbenv $command $ruby
end
end
function rbenv
set -l command $argv[1]
[ (count $argv) -gt 1 ]; and set -l args $argv[2..-1]
switch "$command"
case shell
rbenv_shell $args
case use
rbenv_use $args
case '*'
command rbenv $command $args
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment