Create your first fish shell function

tyler fish photo
By admin on Wed, 02/22/2017 - 14:10

If you have created your own .bashrc scripts and you are trying to migrate those over to fish shell, you'll notice that a .fishrc doesn't exists, you need to create functions and place it inside the fish config folder:

$ ~/.config/fish/functions/

first create a temporary function with the value of 'Hello Friend':

$ alias updateLocalDb 'Hello Friend'

the following command will create the file in your config folder:

$ funcsave updateLocalDb

will save the function to the apropiated folder inside: $ ~/.config/fish/functions/

Edit the new function file that was created for you:

$ vim ~/.config/fish/functions/

Your implementation should look like:

  • put a command per line and do not use ;and

# file: ~/.config/fish/functions/
# Following is just example code
function updateLocalDb     
    echo 'updating local DB start.'     
    echo '////////////////////////'     
    cd ~/myfolder       
    touch myfile.sql    
    echo 'done.'

Execute your new function in a new terminal window:

$ updateLocalDb