Last Updated: February 25, 2016
·
1.201K
· jirichara

Disable version control info in zsh prompt on sshfs mount

Some days ago I wrote big amount of test and because my computer is kinda slow I decided to put the project onto a server (with much more computing power) to do the testing stuff there. To save some time pushing and pulling over and over again, I mounted the directory with my project via sshfs.

sshfs jiri@some.server.com:my_project ~/projects/my_project

So far was everything ok until I tried to cd to the mounted location. My terminal has frozen! Surprisingly I was able to open mounted directory in nautilus. After some research I found the problem - my zsh prompt has done it, because I had some handy git informations there. It takes really LOT of time to get git status over sshfs.

I have hacked my prompt to disable version control info in my prompt when pwd is mounted via sshfs. This is what I came with:

autoload -U colors
autoload -Uz vcs_info

colors
setopt PROMPT_SUBST

zstyle ':vcs_info:*' enable git hg svn
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '%F{green}M%f' 
zstyle ':vcs_info:*' unstagedstr '%F{yellow}M%f'
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
zstyle ':vcs_info:git*' formats " %s %b %m%c%u"

+vi-git-untracked() {
  if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
    git status --porcelain | grep '??' &> /dev/null ; then
    hook_com[unstaged]+='%F{red}?%f'
  fi  
}

precmd () {
  if [[ `stat -f -L -c %T $PWD` == *fuseblk* ]]; then
    echo ""
  else
    vcs_info
  fi
}

PROMPT="%B%~%b %{$fg_bold[red]%}%#%{$reset_color%} "
RPROMPT='%h %n%{$fg_bold[red]%}@%{$reset_color%}%m${vcs_info_msg_0_}'

This is how my prompt looks like:

my zsh prompt

Source