🐠 Fish shell

👋 FYI, this note is over 6 months old. Some of the content may be out of date.
On this page

My Fish config: https://github.com/mrmartineau/fish

Change fish settings:

fish_config

Reload fish shell

fish

Switching to fish? Jump to heading

If you wish to use fish (or any other shell) as your default shell, you need to enter your new shell’s executable in two places.

Add the shell to /etc/shells with:

echo /usr/local/bin/fish | sudo tee -a /etc/shells

ℹ️ homebrew may install fish to /opt/homebrew/bin/fish

Change your default shell with:

chsh -s /usr/local/bin/fish

This assumes you installed fish to /usr/local/bin, which is the default location when you’ve compiled it yourself. If you installed it with a package manager, the usual location is /usr/bin/fish, but package managers typically already add it to /etc/shells. Just substitute the correct location.

(To change it back to another shell, substitute /usr/local/bin/fish with /bin/bash, /bin/tcsh or /bin/zsh as appropriate in the steps above.)

http://fishshell.com/docs/current/tutorial.html
https://github.com/jorgebucaran/fish-cookbook
https://github.com/ghaiklor/iterm-fish-fisher-osx

Fish features Jump to heading

Functions Jump to heading

Create new functions in ~/.config/fish/functions e.g. xyz.fish

Aliases Jump to heading

alias is a simple wrapper for the function builtin, which creates a function wrapping a command.

https://fishshell.com/docs/current/cmds/alias.html

alias gco 'git checkout'
alias undocommit 'git reset HEAD~1'
alias ya 'yarn add'
alias yad 'yarn add -D'

abbr Jump to heading

If you add an abbreviation instead of an alias you’ll get better auto-complete. In fish abbr more closely matches the behavior of a bash alias.

abbr -a gco git checkout

Will add a new abbreviation gco that expands to git checkout.

Fish plugins Jump to heading

Fisher Jump to heading

https://github.com/jorgebucaran/fisher

Plugins are listed in the $__fish_config_dir/fish_plugins file.

Install fisher:

curl -sL https://git.io/fisher | source && fisher install jorgebucaran/fisher

Install a plugin:

fisher install jorgebucaran/[email protected]

Listing plugins

fisher list

Other info Jump to heading

Set shell variables Jump to heading

set -xg PATH /usr/local/sbin $PATH

https://fishshell.com/docs/current/cmds/set.html

Adding to $PATH Jump to heading

Use fish_add_path

fish_add_path /usr/local/sbin

https://fishshell.com/docs/current/cmds/fish_add_path.html

List all $PATH entries Jump to heading

string join \n $PATH | nl

Using ssh-agent Jump to heading

When needing to add ssh keys to Github, the docs suggest running eval "$(ssh-agent -s)" but that does not work in fish. Run this instead:

command ssh-agent -s

Executing Bash Jump to heading

If fish is your default shell and you want to copy commands from the internet that are written in bash (the default shell on most systems), you can proceed in one of the following two ways:

Use the bash command with the -c switch to read from a string:

$ bash -c 'some bash command'

Use bash without a switch to open a bash shell you can use and exit afterward:

> bash
$ some bash command
$ exit

> _

← Back home