Cheat Sheets

Fish Shell

Created: 2017 October 11th

Updated: 2019 March 12th

Edit this page on GitHub

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:

1aliases
2function c --description 'alias c code .'
3function g --description 'alias g git'
4function lss --description 'alias lss ls -lart | sort -k9,9'
5function ni --description 'alias ni npm i'
6function nid --description 'alias nid npm i -D'
7function nig --description 'alias nig npm i -g'
8function no --description 'alias no npm outdated'
9function nog --description 'alias nog npm outdated -g --depth=0'
10function nr --description 'alias nr npm run'
11function nrb --description 'alias nrb npm run build'
12function nrd --description 'alias nrd npm run dev'
13function nrf --description 'alias nrf npm run format'
14function nrs --description 'alias nrs npm run start'
15function nug --description 'alias nug npm -g un'
16function nun --description 'alias nu npm un'
17function r --description 'alias r cd /mnt/d/repos/'
18function yd --description 'alias yd yarn dev'
19function yg --description 'alias yg yarn go'
20function ys --description 'alias ys yarn start'

The following you can copy pate into fish:

1alias c 'code .';funcsave c;alias g 'git';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 nug 'npm -g un';funcsave nug;alias nu 'npm un';funcsave nu;alias r 'cd /mnt/d/repos/';funcsave r;alias yd 'yarn dev';funcsave yd;alias yg 'yarn go';funcsave yg;alias ys 'yarn start';funcsave ys;