Creating a Global Function in Fish shell

A brief overview of how to create a function in fish shell, and run from any location on your machine.

Fish Config Screenshot

Creating a Function:

Navigate to root

cd

Create a simple function using the function keyword

function myFunction
echo “Hello World!”
end

Save the function to the fish config file using funcsave

funcsave myFunction

Thats it! To update your new function continue reading

Updating a function:

Navigate to the fish .config folder

cd ~/.config/fish/functions

Update the function using nano [exit using ctrl+x, y, ENTER] or vim [if you don’t want to exit at all]

nano myFunction.fish

Change the contents of your function :

function myFunction
echo “Welcome to my function!”
end

Parameters & Arguments:

cd ~/.config/fish/functionsnano myFunction.fishfunction myFunction
echo “$argv”
end

Anything passed after your function name can be accessed by using $argv

myFunction foo
>> foo

teacher | full stack web dev | software engineer christopherwatson.co

teacher | full stack web dev | software engineer christopherwatson.co