How to define an alias in fish shell?

前端 未结 10 579
星月不相逢
星月不相逢 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:42

    To properly load functions from ~/.config/fish/functions

    You may set only ONE function inside file and name file the same as function name + add .fish extension.

    This way changing file contents reload functions in opened terminals (note some delay may occur ~1-5s)

    That way if you edit either by commandline

    function name; function_content; end
    

    then

    funcsave name
    

    you have user defined functions in console and custom made in the same order.

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

    For posterity, fish aliases are just functions:

    $ alias foo="echo bar"
    $ type foo
    foo is a function with definition
    function foo
        echo bar $argv; 
    end
    

    To remove it

    $ unalias foo
    /usr/bin/unalias: line 2: unalias: foo: not found
    $ functions -e foo
    $ type foo
    type: Could not find “foo”
    
    0 讨论(0)
  • 2020-12-07 07:48

    This is how I define a new function foo, run it, and save it persistently.

    sthorne@pearl~> function foo
                        echo 'foo was here'
                    end
    sthorne@pearl~> foo
    foo was here
    sthorne@pearl~> funcsave foo
    
    0 讨论(0)
  • 2020-12-07 07:55

    Save your files as ~/.config/fish/functions/{some_function_name}.fish and they should get autoloaded when you start fish.

    0 讨论(0)
提交回复
热议问题