当我的CWD位于远程文件系统上时,如何有选择地禁用zsh的版本控制集成?


16

我在OSX上运行zsh,有时必须在已安装的sshfs卷上工作。但是,git真的比sshfs挂载慢。我的提示使用了zsh提供的内置vc模式的东西,但是在这种情况下,我想跳过该部分。

每当我的CWD位于已挂载的文件系统上时,我想有选择地禁用vc集成。我怎样才能做到这一点?

我目前正在使用(大致).zshrc的摘要在提示符下启用git info(嗯,.oh-my-zsh / themes,但您知道了):

zstyle ':vcs_info:*' enable hg git bzr svn p4

zstyle ':vcs_info:(hg*|git*):*' get-revision true
zstyle ':vcs_info:(hg*|git*):*' check-for-changes true

# rev+changes branch misc
zstyle ':vcs_info:hg*' formats "[%i%u %b%m]"
zstyle ':vcs_info:hg*' actionformats "(%{$fg_bold[red]%}%a%{$reset_color%})[%i%u %b%m]"

# hash changes branch misc
zstyle ':vcs_info:git*' formats "[%{$fg[yellow]%}%12.12i%{$reset_color%} %u %{$fg[magenta]%}%b%{$reset_color%}%m]"
zstyle ':vcs_info:git*' actionformats "(%a)[%{$fg[yellow]%}%12.12i%{$reset_color%} %u %{$fg[magenta]%}%b%{$reset_color%}%m]"

zstyle ':vcs_info:git*+set-message:*' hooks git-st git-stash

zstyle ':vcs_info:hg*:netbeans' use-simple true

zstyle ':vcs_info:hg*:*' get-bookmarks true

zstyle ':vcs_info:hg*:*' get-mq true
zstyle ':vcs_info:hg*:*' get-unapplied true
zstyle ':vcs_info:hg*:*' patch-format " mq(%g):%{$fg[green]%}%n%{$reset_color%}/%{$fg_bold[blue]%}%c%{$reset_color%} %{$fg[green]%}%p%{$reset_color%}"
zstyle ':vcs_info:hg*:*' nopatch-format ""

zstyle ':vcs_info:hg*:*' unstagedstr " ?"
zstyle ':vcs_info:hg*:*' hgrevformat "%{$fg[yellow]%}%r%{$reset_color%}" # only show local rev.
zstyle ':vcs_info:hg*:*' branchformat "%{$fg[magenta]%}%b%{$reset_color%}" # only show branch

# Show remote ref name and number of commits ahead-of or behind
function +vi-git-st() {
    local ahead behind remote
    local -a gitstatus

    # Are we on a remote-tracking branch?
    remote=${$(git rev-parse --verify ${hook_com[branch]}@{upstream} \
        --symbolic-full-name 2>/dev/null)/refs\/remotes\/}

    if [[ -n ${remote} ]] ; then
        # for git prior to 1.7
        # ahead=$(git rev-list origin/${hook_com[branch]}..HEAD | wc -l)
        ahead=$(git rev-list ${hook_com[branch]}@{upstream}..HEAD 2>/dev/null | wc -l | tr -s ' ')
        (( $ahead )) && gitstatus+=( " ${c3}+${ahead}${c2}" )

        # for git prior to 1.7
        # behind=$(git rev-list HEAD..origin/${hook_com[branch]} | wc -l)
        behind=$(git rev-list HEAD..${hook_com[branch]}@{upstream} 2>/dev/null | wc -l | tr -s ' ')
        (( $behind )) && gitstatus+=( " ${c4}-${behind}${c2}" )

        hook_com[branch]="${hook_com[branch]} [${remote}${(j:/:)gitstatus}]"
    fi
}

# Show count of stashed changes
function +vi-git-stash() {
    local -a stashes

    if [[ -s ${hook_com[base]}/.git/refs/stash ]] ; then
        stashes=$(git stash list 2>/dev/null | wc -l)
        hook_com[misc]+=" (${stashes} stashed)"
    fi
}

precmd () { vcs_info }
PROMPT='
%{$(get_prompt_user_color)%}%n%{$reset_color%} at %{$(get_prompt_host_color)%}%m%{$reset_color%} in %{$fg_bold[green]%}%~%{$reset_color%} ${vcs_info_msg_0_}
$(virtualenv_info)$(prompt_char) '


不,这不是完井是一个问题
克里斯- [R

好的,很抱歉收到
Joe Internet,

您可以添加用于启用此功能的相关zshrc部分吗?
多项式

Answers:


9

看看 版本控制信息

搜索有关“禁用模式”的部分(大约在页面下方20%)。
假设您的远程挂载是固定的或相对固定的,即,/mnt/remote/*或者您可以列出它们的全部,那么您应该能够为它们提供一个正则表达式。

在链路的示例中禁用vcs_info~/.zsh/,通过:

zstyle ':vcs_info:*' disable-patterns "$HOME/.zsh(|/*)"

我猜你可以让zshrc或等效的对象(对不起-bash用户)找出启动时(或定期或...)是远程的,并相应地进行更新zstyle

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.