Cheat Sheets

Fish Shell

Created: 2017 October 11th

Updated: 2020 August 26th

Edit this page on GitHub

NVM not recognised in Fish?

Install the Oh My Fish package nvm with:

1omf install nvm

Aliases

Quick list for aliasing:

1functions aliasname
2# Displays function contents
3
4functions -n
5# Displays a list of currently-defined functions
6
7functions -c newalias aliasname
8# Copies the 'aliasname' function to a new function called 'newalias'
9
10functions -e aliasname
11# Erases the function `aliasname`

To list what aliases you have already defined:

1ls -la ~/.config/fish/functions/

To see what is contained in the functions, use:

1type functionName
2# or use functions
3functions functionName

To create an alias:

1# Sort alphabetically
2alias lss 'ls -lart | sort -k9,9'

To save said alias:

1funcsave lss

View the contents of the function:

1functions lss
2# output
3# Defined in /home/scott/.config/fish/functions/lss.fish @ line 2
4function lss --description 'alias lss ls -lart | sort -k9,9'
5 ls -lart | sort -k9,9 $argv;
6end

To remove an alias:

1rm ~/.config/fish/functions/aliasname.fish

or use:

1functions -e aliasname

Oh My Fish

https://github.com/oh-my-fish/oh-my-fish

Use nvm with fish

If you have Oh My Fish installed then install the bass plugin:

1omf install bass

Then add the following to your config.fish file:

1function nvm
2 bass source (brew --prefix nvm)/nvm.sh --no-use ';' nvm $argv
3end
4
5set -x NVM_DIR ~/.nvm
6nvm use default --silent

Then source the config.fish file:

1source ~/.config/fish/config.fish

List out added aliases

I found this handy function on Stack Overflow which will list out your functions:

1function aliases --description "list all fish aliases";for f in (functions);functions $f | grep \'alias;end;end;

Then you save it funcsave aliases and use it funcsave the output will be:

1aliases
2function c --description 'alias c code .'
3function g --description 'alias g git'
4...

The following you can copy paste into fish:

1alias c 'code .';funcsave c;alias e exit;funcsave e;alias g hub;funcsave g;alias lss 'ls -lart | sort -k9,9';funcsave lss;alias ni 'npm i';funcsave ni;alias nid 'npm i -D';funcsave nid;alias nig 'npm i -g';funcsave nig;alias no 'npm outdated';funcsave no;alias nog 'npm outdated -g --depth=0';funcsave nog;alias nr 'npm run';funcsave nr;alias nrb 'npm run build';funcsave nrb;alias nrd 'npm run dev';funcsave nrd;alias nrf 'npm run format';funcsave nrf;alias nrs 'npm run start';funcsave nrs;alias nu 'npm un';funcsave nu;alias nug 'npm -g un';funcsave nug;alias pp 'git pull && git push';funcsave pp;alias r 'cd ~/repos';funcsave r;alias ya 'yarn add';funcsave ya;alias yad 'yarn add -D';funcsave yad;alias yb 'yarn build';funcsave yb;alias ybycys 'yarn clean && yb && yarn serve';funcsave ybycys;alias yd 'yarn dev';funcsave yd;alias yg 'yarn go';funcsave yg;alias yga 'yarn global add';funcsave yga;alias yr 'yarn remove';funcsave yr;alias ys 'yarn start';funcsave ys;alias yyb 'yarn && yarn build';funcsave yyb;alias yyd 'yarn && yarn dev';funcsave yyd;