How to create alias in Fish

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

Advertisements

3 thoughts on “How to create alias in Fish

  1. how can I define git command example
    function stt
    git status
    end

    I tried like that but git command not working

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.