A journey into fish

Getting fish shell ready for Ruby coding

Alexander Greim

--

Terminal shells are essential. They let you communicate with your operating system underneath the user interface. Also it’s “the tool” for developers that value flexibility and speed over user interfaces. But shells don’t have to be as clunky as bash or heavily extended like oh-my-zsh on top of z-shell.

Fish shell is thin and user-friendly. Out of the box you get features that make your live easier and more fun. Even though it is not fully posix compatible it’s getting an increasing level of support by the community. And it’s refreshingly different.

Installation

Installing fish shell is as easy as installing any other Homebrew package.

$ brew install fish

Starting fish shell from your running shell is as easy as well.

$ fish

Customization

Fish can be customized by editing it’s user-specific configuration file.

$ vim ~/.config/fish/config.fish

It’s a bright idea using that path. It makes versioning and portable profiles much easier than picking up config files placed directly in the home directory.

Supporting Homebrew

Integrating Homebrew means ensuring it’s binaries are found before the system ones in the search path. Fish uses the “set” syntax other than “export” in zsh or bash. Also $PATH is not a string of semicolon separated path entries. It’s an array where entries are delimited by white-spaces.

Knowing that, prepending the Homebrew binary path translates to

set -x PATH /usr/local/bin $PATH

Add this line to your config.fish file. It’s all you have to do.

Getting rbenv running

Rbenv is my favorite version manager for Ruby installations. It initializes by defining itself as a function via shell scripting in every shell session. So far it needs quite some hacking to get it working with fish. Fortunately @mislav recently added fish shell support. As it didn’t went into a release yet, you need to install the HEAD revision of rbenv.

$ brew unlink rbenv$ brew install --HEAD rbenv

After that add the following line to your config.fish file.

set PATH $HOME/.rbenv/bin $PATH
. (rbenv init -|psub)

Now your are able to switch Ruby versions as usual.

Enabling the git prompt

Fish shell has a baked-in git prompt support. It’s a handy feature to see the status of the repository you are working on. Version 2.0 released by date needs quite some configuration settings if you want to use the full status including stashes, upstreams and untracked files.

Good news it that the master version already contains one provides on single and well composed configuration default putting it all together. Again this version is not released yet. So you need to install the HEAD of the fish.

$ brew unlink fish$ brew install --HEAD fish

Then enable the git prompt in your config.fish file.

set __fish_git_prompt_show_informative_status ‘yes’

Use some color for the branch if you like.

set __fish_git_prompt_color_branch yellow

Finally set the fish prompt including the git part.

function fish_prompt
set last_status $status
set_color $fish_color_cwd
printf '%s' (prompt_pwd)
set_color normal
printf '%s ' (__fish_git_prompt) set_color normal
end

Conclusion

It took me some time to put that all together. Especially finding out about what’s possible and still unreleased. My goal was to keep the configuration as simple as possible. You can find it in my repository.

The most interesting part is still pending — using fish on a daily basis.

--

--