Fish shell:如何在提示中禁用“git status”?

问题描述 投票:0回答:2

我喜欢 Fish 在提示中显示“git status”。然而,它对于非常大的 git 存储库来说效果不佳,因为它非常慢。如何根据目录名称禁用此功能?谢谢!

fish
2个回答
3
投票

这就是我所做的。您需要更换那些

<REPO>

function fish_prompt
  set last_status $status

  set_color $fish_color_cwd
  printf '%s ' (prompt_pwd)
  set_color normal

  set BIG_REPOS <REPO1> <REPO2> <REPO3>
  if not contains (basename $PWD) $BIG_REPOS
    printf '%s ' (__fish_git_prompt)
  end

  set_color normal
end

0
投票

查看

fish_git_prompt
函数的开头,它会检查防护函数
__fish_git_prompt_ready
:

mjl@modi ~> functions fish_git_prompt|head
# Defined in /opt/homebrew/Cellar/fish/3.7.0/share/fish/functions/fish_git_prompt.fish @ line 194
function fish_git_prompt --description 'Prompt function for Git'
    # If git isn't installed, there's nothing we can do
    # Return 1 so the calling prompt can deal with it
    if not command -sq git
        return 1
    end
    # Fail if __fish_git_prompt_ready is defined and fails.
    if functions -q __fish_git_prompt_ready && not __fish_git_prompt_ready
        return 1

由于在 tmux 中我安装了 tmux powerline,因此我也不需要在 Fish shell 提示符上显示 git status。 Tmux 还以异步方式运行 git 提示。我已经编写了

__fish_git_prompt_ready
函数来在不需要时在提示中禁用 git:

mjl@modi ~> functions __fish_git_prompt_ready
# Defined in /Users/mjl/.config/fish/functions/__fish_git_prompt_ready.fish @ line 1
function __fish_git_prompt_ready
  not set --query TMUX
end

你可以写一个类似的(和

funcsave __fish_git_prompt_ready
)。也许检查 CWD 不是您非常慢的项目之一,就像 @jduan 所做的那样:

function __fish_git_prompt_ready
  if not set --query BIG_GIT_REPOS
    set BIG_GIT_REPOS <repo1> <repo2> <repo3>
  end
  not contains (basename $PWD) $BIG_GIT_REPOS
end

这会查找变量

BIG_GIT_REPOS
,如果未定义,则回退到硬编码集。

© www.soinside.com 2019 - 2024. All rights reserved.