Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to create alias in Fish

📅 2014-Feb-27 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

To create an alias in the fish shell, just create a function of that name:

function ll
    ls --human-readable -l
end

You can place this function inside ~/.config/fish/config.fish file. Or you can place it in a new file named ll.fish in the directory ~/.config/fish/functions/.

To pass the arguments that come after the alias to the underlying command, use the $argv variable:

function ll
    ls --human-readable -l $argv
end

If you name the alias with the same name as the command, then you get this error at the shell:

fish: The function calls itself immediately, which would result in an infinite loop.

So, if you want to reuse the name of a command for the alias, then invoke it using the command. In this example, the alias is named as ls and it invokes ls:

function ls
    command ls --human-readable -l $argv
end

If you prefer to use the alias command of bash, you can use that instead:

alias ll="ls --human-readable -l"

Since an alias is just a function in fish, you can view the list of aliases by listing the functions:

$ functions

To see what a particular alias is defined as, list the code of that function:

$ functions ll

Tried with: fish 2.1.0 and Ubuntu 12.04 LTS