How to define an alias in fish shell?

前端 未结 10 578
星月不相逢
星月不相逢 2020-12-07 06:56

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 g

相关标签:
10条回答
  • 2020-12-07 07:32

    Just use alias. Here's a basic example:

    # Define alias in shell
    alias rmi "rm -i"
    
    # Define alias in config file
    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
    

    This last command creates the file ~/.config/fish/functions/rmi.fish.

    Interested people might like to find out more about fish aliases in the official manual.

    0 讨论(0)
  • 2020-12-07 07:34

    If you add an abbr instead of an alias you'll get better auto-complete. In fish abbr more closely matches the behavior of a bash alias.

    abbr -a gco git checkout
    

    Will -add a new abbreviation gco that expands to git checkout.

    Here's a video demo of the resulting auto-complete features

    0 讨论(0)
  • 2020-12-07 07:36

    make a function in ~/.config/fish/functions called mkalias.fish and put this in

    function mkalias --argument key value
      echo alias $key=$value
      alias $key=$value
      funcsave $key
    end
    

    and this will create aliases automatically.

    0 讨论(0)
  • 2020-12-07 07:38

    fish starts by executing commands in ~/.config/fish/config.fish. You can create it if it does not exist:

    vim ~/.config/fish/config.fish

    and save it with :wq

    step1. make configuration file (like .bashrc)

    config.fish

    step2. just write your alias like this;

    alias rm="rm -i"

    0 讨论(0)
  • 2020-12-07 07:38
    1. if there is not config.fish in ~/.config/fish/, make it.
    2. there you can write your function .function name; command; end
    0 讨论(0)
  • 2020-12-07 07:39

    I found the prior answers and comments to be needlessly incomplete and/or confusing. The minimum that I needed to do was:

    1. Create ~/.config/fish/config.fish. This file can optionally be a softlink.
    2. Add to it the line alias myalias echo foo bar.
    3. Restart fish. To confirm the definition, try type myalias. Try the alias.
    0 讨论(0)
提交回复
热议问题