Skip to content

Instantly share code, notes, and snippets.

@originell
Last active January 11, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save originell/3f5526c15600824cc9a4050d935ff4f8 to your computer and use it in GitHub Desktop.
Save originell/3f5526c15600824cc9a4050d935ff4f8 to your computer and use it in GitHub Desktop.
Small Fish Intro

fish quickstart

  • You can install fish via most popular package managers (macos: brew install fish). Make sure it's fish 3 though, as it added tons of syntax which make it a bit more "bash-friendly")
  • Make sure to also use a manager for your fish scripts. Personally, I like fisher
  • Have a read through awesome-fish. A collection of some nice tools
  • Make sure you understand how fish handles $PATH differently. See the Path.md in this gist.

Below is a list of fish-packages I'm also using. That's it. Git autocompletion, command suggestions, reverse search, ssh autocompletion,… Everything should be working out of the box and super fast. Most tools nowadays already install fish compatible completions (pyenv,…).

Fisher packages I'm using

# super fast nvm wrapper. doesn't support labels though.
# (which I don't need)
brigand/fast-nvm-fish

# bash compatibility layer. you might not need this.
# most scripts have a shebang for /bin/bash anyways, so you probably won't.
edc/bass

# I really _love_ https://github.com/sindresorhus/pure
# sadly, there is no feature complete fish port yet but this is quite close.
rafaelrinaldi/pure

That's it. You can install them via $ fisher add.

One thing I'm still missing from my old zsh setup is fzf. However, that should be fairly easy to integrate.

# File: .config/fish/config.fish
# Note: See that I'm not doing any $PATH modifications here?
# That is because fish has the excellent "set -U".
# More details in the PATH.md
## Aliases
# move files to macos trash
alias rm='rmtrash'
# "next generation" ls
alias ls="exa"
alias l="exa"
## Python
# pyenv support
status --is-interactive; and source (pyenv init -|psub)
## Node
# use latest lts by default.
nvm use 10.15.0

Notes about $PATH

You are probably used to lines like these in your shell config:

export PATH="/usr/local/opt/gettext/bin:$PATH"

Now, $PATH can also be modified like this in fish. However, it would not be very idiomatic.

Adding to $PATH–the fish way

Fish has three excellent ideas:

  • "Lists" are a thing. No more foo:bar:baz.
  • Why not simply allow users to prepend to another variable instead of modifying the global $PATH.
  • Changing variables shouldn't be in your config. Persistency is done automatically.

So. Instead of doing the export thing. Simply execute this in your terminal. I'm using gettext on MacOS as an example:

## Prepend a new bin folder.
# * Separated by spaces as fish_user_paths is a list/array and fish can handle that
# * -U (from `man set`): -U or --universal causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current user's fish instances on the current computer, and will be preserved across restarts of the shell.
set -U fish_user_paths /usr/local/opt/gettext/bin $fish_user_paths

If you are curious, you can verify that this has indeed been written to ~/.config/fish/fish_variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment