将鱼函数指定给另一个名称

时间:2013-12-13 17:07:03

标签: shell fish

我正在尝试自定义fish_prompt,我想调用之前的fish_prompt。我该怎么做:

function fish_prompt
    echo -n "(something)"
    fish_prompt
end

我试过这样:

alias fish_prompt2 fish_prompt

function fish_prompt
    echo -n "(something)"
    fish_prompt2
end

但是别名没有帮助。它只创建一个别名并导致递归。有没有办法将函数分配给其他名称(fish_promptfish_prompt2

1 个答案:

答案 0 :(得分:4)

来自man functions

--copy OLDNAME NEWNAME creates a new function named NEWNAME,
using the definition of the OLDNAME function

所以你应该写:

functions --copy fish_prompt fish_prompt2

然后以你写的方式提供fish_prompt。