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

Fish is a command line shell for Mac OS and Linux. It comes built in with various theme configurations, text-expanding abbreviations, and custom functions that can be run globally on your machine. This article will go over a quick way to set up 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

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
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

Use functions at any location in the Fish Shell!

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

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