如何找到定义 fish 函数的文件?

How to find the file defining a fish function?

摆弄fish_vi_key_bindings,我很想知道这个函数是在哪里定义的。我的直觉是 ~/.config/fish/functions 之外的文件中定义了函数,但我看不到它们。

我如何知道该函数的定义位置?像

function funcfile the-func -d 'show the file for a function'
    ...
end

从 fish 2.6.0 开始,functions 内置函数有一个“--details”选项可以显示:functions --details fish_vi_key_bindings.

在此之前,您只需搜索 $fish_function_path 即可找到第一个匹配项。例如。使用 GNU grep:

grep --files-with-matches "function fish_vi_key_bindings" $fish_function_path/*.fish

My intuition is that functions exist defined in files outside of ~/.config/fish/functions, but I can't see them.

你的想法是正确的。您可能正在考虑的是 $fish_function_path。这是一个包含 fish 搜索函数的目录的列表,在第一个匹配处停止。