是否可以用 fish 中使用相同名称的另一个函数包装现有函数?

Is it possible to wrap an existing function with another function using the same name in fish?

我想创建一个 cd 函数,它扩展了(在我的机器上)位于 /usr/local/Cellar/fish/2.6.0/share/fish/functions/cd.fish 的当前 cd 函数。这可能吗?

所以像这样:

function cd
    if i_can_handle_it
        do_my_thing_with $argv
    else
        call /usr/local/Cellar/fish/2.6.0/share/fish/functions/cd.fish $argv
    end
end

不能有两个同名的函数。您可以拥有同名的内置命令、函数和外部命令。这个问题的标准解决方法是先将要包装的函数重命名为:functions -c cd cd2。然后定义调用 cd2cd 函数。请注意,无论 cd 是否已经被 运行 定义,这都有效,因为首先更改名称会导致它被自动加载。