Rbenv: Shims for Fish shell

Created on 16 Feb 2012  ·  20Comments  ·  Source: rbenv/rbenv

It would be very helpful is rbenv provided shims that were also fish shell compatible. It wouldn't be a huge change, but it'd mean that rbenv could be used in a non-bash/zsh shell. The syntax for fish is actually much more sane than bash.

Most helpful comment

Seems the shims are fine, it's the install guide that needs tweaking. Add this to config.fish for rbenv support:

set PATH $HOME/.rbenv/bin $PATH
set PATH $HOME/.rbenv/shims $PATH
rbenv rehash >/dev/null ^&1

All 20 comments

I'd like to put in my support for this.

Seems the shims are fine, it's the install guide that needs tweaking. Add this to config.fish for rbenv support:

set PATH $HOME/.rbenv/bin $PATH
set PATH $HOME/.rbenv/shims $PATH
rbenv rehash >/dev/null ^&1

Thanks, Ed! :)

Works like a charm.
You are a gentleman and a scholar.

As @emcmanus pointed out, rbenv's shims work fine with Fish or any other shell. You only need Bash _installed_ to use them—it doesn't need to be your shell. The shims are Bash scripts, and you can run them from Fish in the same way that you can run a Ruby or Python script from Fish.

Adding rbenv to your PATH is all that's necessary for it to work. I would accept a patch that adds Fish compatibility for rbenv init so you don't need to manually construct the paths.

It looks like this isn't enough though, since rbenv shell won't work.

rbenv shell is just a shortcut for setting the RBENV_VERSION environment variable. You don't lose any functionality without it.

I used this to get rbenv shell to work in fish: https://coderwall.com/p/6hja1w

When invoking rbenv from fish shell, no environment variables set in your shell are passed. What's more, neither ~/.bashrc nor ~/.bash_profile are read. If you want to customize rbenv, see #375.

@espen has mentioned mine Coderwall protip, but there is updated version that allow partial Ruby name (the default will be choosen the newest one, still without completion). The Gist can be found there https://gist.github.com/5631243 (give it some love if you can).

I understand that this issue has now been closed but I still wonder if we could get this feature implemented the right way. Am I right thinking that we'd only need to make sure that when rbenv init - is called then it should echo fish shell friendly syntax so that fish will be able to evaluate that? In which case I'd rather have it implemented as part of the original rbenv repo than having external _workarounds_ that might get out of sync with the original internals of rbenv...

I also understand that @sstephenson might not want to actively support the fish shell but perhaps we could try to implement an experimental compatibility in the beginning and I'm sure could get support from the fish shell community itself (they seem to be quite friendly and quite responsive as well).

Presumably the file we'd need to change is https://github.com/sstephenson/rbenv/blob/master/libexec/rbenv-init
Am I right? I'm not a shell script magician but I'd rather attempt to do it right in collaboration with somebody if one's up to doing this the right way.

Cheers

Any fish user is welcome to improve the output of rbenv init so that it supports fish shell and send us a pull request.

Problem is that fish isn't POSIX shell and it will be hard to implement rbenv init in right way to provide support to fish (I assume that there will be then some will want support for csh or tcsh). I think that it should be noted that if someone use non-POSIX shell then he can use one of community functions (and give a links) or (s)he must write it by himself/herself.

@hauleth I think you _may be_ mistaken. Based on the comments from @emcmanus and @sstephenson all we need to do is to get rbenv init to produce fish compatible syntax so that it can be evald by fish. A POSIX compatible shell (like bash for that manner) just needs to be installed and not necessarily have to be the shell of your choice. See the comments by @sstephenson above.

I'll fire off an email to the fish community mailing list and initiate the conversation, will try to get some help from the guys there.

The original rbenv shell command calls rbenv sh-shell, which returns a string that is also evald. We could work around it and parse the return code of that call instead of evaling the returned string. Would that be okay? If yes, I could create something that would do this.

@bitboxer Fish shell should be fully supported by rbenv master. If you find that's not the case, please open a new issue. Thanks!

Thank you "emcmanus"
I use fish and was looking for an answer.

As "emcmanus" mentioned, if you are using fish shell then the following worked for me.

TESTED IN

  • Debain
  • Ubuntu
  • Kubuntu
  • Fedora
  • CentOS
  • RedHat Enterprise
vi ~/.config/fish/config.fish
  set PATH $HOME/.rbenv/bin $PATH
  set PATH $HOME/.rbenv/shims $PATH
  rbenv rehash >/dev/null ^&1

Then exit fish and reload fish or just log off and back on again. If can't find the file then that means you just installed fish and did not ran it once. Just run fish and that folder will be created (file may not).

This is fishfish not fish.
http://fishshell.com/

Thanks @emcmanus and @sstephenson.

Apparently the ^ syntax will be deprecated in the future and is broken in some versions (see this issue here).

Therefore it may be better to use the following syntax instead: rbenv rehash >/dev/null >2&1.

Therefore it may be better to use the following syntax instead: rbenv rehash >/dev/null >2&1.

There's a typo in there 2 and > should be swapped:

rbenv rehash >/dev/null 2>&1
Was this page helpful?
0 / 5 - 0 ratings

Related issues

vennsoh picture vennsoh  ·  4Comments

dazza-codes picture dazza-codes  ·  4Comments

ghost picture ghost  ·  4Comments

HuckyDucky picture HuckyDucky  ·  4Comments

sgnd picture sgnd  ·  3Comments