TIDE 中的鱼壳 git_prompt

问题描述

是否可以强制 Fish shell 扩展 TIDE 使用 fish_git_prompt 而不是它自己的 _tide_item_git.fish

我的目标是使 TIDE git 提示与此 tutorial 相同。

现在使用认的 TIDE 设置,我有这个 git 提示

enter image description here

不过,我想让它看起来像这样,但仍然使用 TIDE:

enter image description here

Source image


鱼,版本 3.2.1

Fedora 33

解决方法

那么tide函数所做的就是简单地收集git信息并打印出来。潮汐会调用它,取下它打印的内容,然后将其放置在正确的位置。这也是 fish_git_prompt 的工作方式 - 它打印 git 内容,您的提示负责将其放在正确的位置。

简化:

function fish_prompt
    set gitstuff (_tide_item_git)
    # do other tide stuff
    printf '%s' $gitstuff $otherstuff
end

fish 调用一个函数时,它会通过 $fish_function_path 找到一个带有函数名(加上“.fish”后缀)的文件。

因此,您只需创建自己的函数 _tide_item_git,并将其放在 $fish_function_path 的第一个位置。

我不确定你是如何安装tide的,我假设它不是直接在~/.config/fish/functions——函数的普通目录。这是最简单的情况,因此您只需调用 funced _tide_item_git,它将在您的编辑器中打开它,并将其替换为

function _tide_item_git
    fish_git_prompt
end

然后在您开心时运行 funcsave _tide_item_git

在更复杂的情况下,为您的函数创建另一个目录 - ~/.config/fish/myfunctions 也许 - 将其添加到 $fish_function_path:

set -g fish_function_path ~/.config/fish/myfunctions $fish_function_path

(把它放在 config.fish 中)

在那里创建一个名为 _tide_item_git.fish 的文件并将上述函数放入其中。