我在这个问题上浪费了一些时间,所以我正在创建这个问答系统。
我正在使用一个omf主题,我想在主题提示符中做一个更改。不幸的是,通过设置主题配置变量,我想做的更改是不可能的。
我尝试使用fish_prompt编辑funced fish_prompt; funcsave fish_prompt函数,但是如果这样做,主题就不会再加载了,所以我不能使用在主题中定义的函数。如果我只是在我的fish_prompt中创建一个config.fish函数,也会发生同样的情况。
发布于 2022-05-03 11:26:26
tldr
在定义自己的fish_prompt函数之前添加以下行
source $OMF_PATH/init.fish
# Read current theme
test -f $OMF_CONFIG/theme
and read -l theme < $OMF_CONFIG/theme
or set -l theme default
set -l theme_functions_path {$OMF_CONFIG,$OMF_PATH}/themes*/$theme/functions/
for conf in $theme_functions_path/*.fish
source $conf
end解释
加载omf时,它将主题函数文件添加到$fish_function_path中。(源代码)
根据鱼类文献
当fish需要加载一个函数时,它会在list变量$fish_function_path中的任何目录中搜索一个文件,该文件的名称由函数的名称加上后缀.fish组成,并加载它找到的第一个文件。
文档没有明确说明的是,如果函数已经定义(例如,在config.fish中),它将不会尝试从$fish_function_path加载。
所以问题是,当您创建自己的fish_prompt函数时,它会隐藏.../<theme>/functions/fish_prompt.fish。
要解决这个问题,您需要做的是在重新定义主题函数文件之前强制加载它。例如:
# Read current theme
test -f $OMF_CONFIG/theme
and read -l theme < $OMF_CONFIG/theme
or set -l theme default
set -l theme_functions_path {$OMF_CONFIG,$OMF_PATH}/themes*/$theme/functions/fish_prompt.fish
for conf in $theme_functions_path
source $conf
end
function fish_prompt
# prompt_theme_foo
# prompt_theme_bar
end确保在omf init.fish加载之后运行它。
您可以通过手工获取source $OMF_PATH/init.fish或确保omf.fish的字母顺序小于您的文件来确保。
https://stackoverflow.com/questions/72098696
复制相似问题