linuxshellfish

Define an alias in fish shell


I would like to define some aliases in fish. Apparently it should be possible to define them in

~/.config/fish/functions

but they don't get auto loaded when I restart the shell. Any ideas?


Solution

  • Just use alias. Here's a basic example:

    # Define alias in shell
    alias rmi "rm -i"
    
    # Define alias in config file ( `~/.config/fish/config.fish` )
    alias rmi="rm -i"
    
    # This is equivalent to entering the following function:
    function rmi
        rm -i $argv
    end
    
    # Then, to save it across terminal sessions:
    funcsave rmi
    
    # or, since Fish 3.0, define and save all at once:
    alias --save rmi="rm -i"
    

    The command funcsave creates the file ~/.config/fish/functions/rmi.fish. This is handled automatically when using the newer alias --save syntax.

    More info about Fish aliases can be found in the official manual.