WSL-config icon indicating copy to clipboard operation
WSL-config copied to clipboard

Slow prompt command (oh-my-zsh)

Open ofenerci opened this issue 5 years ago • 18 comments

I followed your instructions but I ended up a very slow command prompt from Zsh. It takes almost a second for the prompt to show again. Is there a way to make it faster?

ofenerci avatar Apr 03 '19 12:04 ofenerci

Since writing that post I've pretty much completely abandoned WSL and have fully switched to Arch for the past year.

However, I do remember that my setup was a bit slow as well. I assume this has to do with .zshrc and sourcing it every time the terminal is started.

What I would recommend, is to remove and reinstall zsh and oh-my-zsh. This time fully abandon antigen, as it's not developed anymore. I probably had a reason for using at the time but don't anymore! Oh-my-zsh has an easy plugin syntax now:

plugins=(
  git
  autojump
  dirhistory
  fasd
  history-substring-search
  zsh-syntax-highlighting
  zaw
  wd
)

I also remember zsh-history-substring-search was an expensive plugin and had performance issues. So maybe remove it. Above are all the plugins I use and zsh seems to be pretty fast and snappy.

The rest of the setup should be irrelevant to the startup time. But again for your info, VSCode is a fantastic CPP development environment. Moreover, it has great integration for the development of CPP using WSL in a *nix environment where you run and debug from WSL but interface and code on Windows using VSCode. So I would abandon vim and investigates this as well.

Good luck with 4400

hsab avatar Apr 03 '19 18:04 hsab

This is my entire .zshrc now:

# Path to your oh-my-zsh installation.
export ZSH="/home/***/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

# POWERLEVEL9K_MODE='awesome-fontconfig'

ZSH_THEME="powerlevel9k/powerlevel9k"


# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
  autojump
  dirhistory
  fasd
  history-substring-search
  zsh-syntax-highlighting
  zaw
  wd
)

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda dir vcs)

source $ZSH/oh-my-zsh.sh

setopt correct
bindkey '^R' zaw-history

hsab avatar Apr 03 '19 18:04 hsab

Hello, I have the same issue. After update to WLS 2 the ZSH and GIT are slowing things down to a point where I wait 10s before I can cd in the directory. Nothing has helped

mp3por avatar Jan 20 '20 09:01 mp3por

Scott Hanselman comments on this problem in the article below

Do your Linux source code/git work in the Linux filesystem for speed until WSL2 gets the file system faster under /mnt

See the GOTCHA towards the end of the article: https://www.hanselman.com/blog/HowToMakeAPrettyPromptInWindowsTerminalWithPowerlineNerdFontsCascadiaCodeWSLAndOhmyposh.aspx

johndbell avatar Jan 24 '20 15:01 johndbell

same issue with @mp3por

Redshoee avatar Feb 20 '20 10:02 Redshoee

I found a simple solution. this solution are temporary solution but well works.

 git config --global oh-my-zsh.hide-status 1

cloverhearts avatar Jun 16 '20 14:06 cloverhearts

I had this same issue when using zsh-syntax-highlighting plugin in a WSL2 installation (had no problems with WSL1 whatsoever). Disabled the plugin and the prompt was fast again.

victor-borges avatar Jun 24 '20 18:06 victor-borges

Scott Hanselman comments on this problem in the article below

Do your Linux source code/git work in the Linux filesystem for speed until WSL2 gets the file system faster under /mnt

See the GOTCHA towards the end of the article: https://www.hanselman.com/blog/HowToMakeAPrettyPromptInWindowsTerminalWithPowerlineNerdFontsCascadiaCodeWSLAndOhmyposh.aspx

I copied over my code directory into my linux home directory and it is blazing fast now! I was able to re-enable all of my git prompts! The copy took forrrrevvvver, but once that was done all git actions, git prompts, and tab completes are super quick now. Here's the screenshot of the note mentioned in the comment above:

image

CompSciMaj13 avatar Aug 13 '20 22:08 CompSciMaj13

There's another gotcha. WSL automatically adds stuff to PATH pointing to windows directories. This can bring auto complete to a hold. Solution: disabling this part of auto complete or disabling PATH modification by WSL.

trallnag avatar Sep 19 '21 19:09 trallnag

git config --global oh-my-zsh.hide-info 1 Updated command to disable oh-my-zsh git prompt magic.

Root cause is WSL using the slow 9P protocol to access Windows drive. ref. https://stackoverflow.com/a/68974497/135962

andywatts avatar Mar 02 '22 21:03 andywatts

Scott Hanselman comments on this problem in the article below

Do your Linux source code/git work in the Linux filesystem for speed until WSL2 gets the file system faster under /mnt

See the GOTCHA towards the end of the article: https://www.hanselman.com/blog/HowToMakeAPrettyPromptInWindowsTerminalWithPowerlineNerdFontsCascadiaCodeWSLAndOhmyposh.aspx

I copied over my code directory into my linux home directory and it is blazing fast now! I was able to re-enable all of my git prompts! The copy took forrrrevvvver, but once that was done all git actions, git prompts, and tab completes are super quick now. Here's the screenshot of the note mentioned in the comment above:

image

This is what solved my problem.

scardenasb avatar Mar 23 '22 06:03 scardenasb

@scardenasb That's the real reason

ShinJustinHolly3317 avatar Aug 27 '22 04:08 ShinJustinHolly3317

I disabled the git prompt in /mnt directory and it works.

 --git a/lib/git.zsh b/lib/git.zsh
index f049f73..1c4ee23 100644
--- a/lib/git.zsh
+++ b/lib/git.zsh
@@ -10,6 +10,9 @@ function __git_prompt_git() {
 }

 function git_prompt_info() {
+
+  [[ "$PWD" =~ "^/mnt.*" ]] && return 0
+
   # If we are on a folder not tracked by git, get out.
   # Otherwise, check for hide-info at global and local repository level
   if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
@@ -38,7 +41,9 @@ function parse_git_dirty() {
   local STATUS
   local -a FLAGS
   FLAGS=('--porcelain')
-  if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]; then
+  if ([[ "$(__git_prompt_git config --get oh-my-zsh.hide-dirty)" != "1" ]]) \
+          && ! [[ "$PWD" =~ "^/mnt.*" ]];
+  then
     if [[ "${DISABLE_UNTRACKED_FILES_DIRTY:-}" == "true" ]]; then
       FLAGS+='--untracked-files=no'
     fi
@@ -162,6 +167,7 @@ function git_prompt_long_sha() {
 }

 function git_prompt_status() {
+  [[ "$PWD" =~ "^/mnt.*" ]] && return
   [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return

   # Maps a git status prefix to an internal constant

ethanchanus avatar Feb 24 '23 17:02 ethanchanus

I came here for the same issue and I quickly realized it was the git stuff sloing everything down. Was jsut wondering if anyone would have any ideas on how I could make it use the windows git.exe for this stuff instead when on an ntfs drive. It could detect this with wslpath command.

eg.

if wslpath -w . | grep -q '\\wsl'; then
    #use regular git
elif
   #use git.exe instead
fi

ideas on how this could work?

b-hayes avatar Jun 24 '23 10:06 b-hayes

@b-hayes & @Lucas-Ten

I overrode the function implementation after OhMyZsh was loaded. It looks as follows:

oh-my-zsh-git-patch.sh

__git_prompt_git() {
  if wslpath -w . | grep -q '\\wsl'; then
    echo git $@
  else
    echo powershell.exe git.exe --no-optional-locks $@
  fi
}

In my .zshrc:

# After: 
source $ZSH/oh-my-zsh.sh

# Insert:
export MICROSOFT_UNAME=$(uname -a | grep -i microsoft)
export IS_WSL=$( [ ! -z "$MICROSOFT_UNAME" ] && echo "1" || echo "0" )

if [[ "$IS_WSL" == "1" ]]; then
  source $PERSONAL_SHELL_SETUP_PATH/wsl/oh-my-zsh-git-patch.sh
fi

Alternative: Use the original script instead, but create an alias called git instead. (With the same implementation as above). this way, all other tools would access the windows git version, too (including vscode).

You can also see the fix integrated in my shell-setup repo here: https://github.com/Hobart2967/shell-setup/commit/291fcb53f10f5e97db5e54682c85247dfa30909f

Hobart2967 avatar Jun 27 '23 22:06 Hobart2967

@Hobart2967 Using your prompt I get the following result displayed:

➜  ~ git:(git symbolic-ref --short HEAD) ✗

I did end up creating an alias to my own script tho and that seems to work well. Here is what im using as my git replacement:

#!/usr/bin/env bash

# To speed up git on WSL use this as an alias for git.
# Dynamically switches to the windows executable when it detects its not on wsl file system.
if wslpath -w . | grep -q '\\wsl'; then
    #echo "switched to /usr/bin/git"
	/usr/bin/git $@
else
    #echo "switched to git.exe"
    git.exe $@
fi

b-hayes avatar Jul 08 '23 03:07 b-hayes

My current setup

source $ZSH/oh-my-zsh.sh

export MICROSOFT_UNAME=$(uname -a | grep -i microsoft)
export IS_WSL=$( [ ! -z "$MICROSOFT_UNAME" ] && echo "1" || echo "0" )

if [[ "$IS_WSL" == "1" ]]; then
  __git_prompt_git() {
    if wslpath -w . | grep -q '\\wsl'; then
      git --no-optional-locks $@
    else
      git.exe --no-optional-locks $@
    fi
  }
fi

jnguyen1098 avatar Jul 09 '23 21:07 jnguyen1098

Another way to solve this issue is to choose a zsh theme that doesn't use the git plug-in. You can find theme without git_promt using the following:

$ cd ~/.oh-my-zsh/themes 
$ grep --files-without-match "git" *  
cypher.zsh-theme
duellj.zsh-theme
evan.zsh-theme
funky.zsh-theme
imajes.zsh-theme
jtriley.zsh-theme
mikeh.zsh-theme
random.zsh-theme
rkj.zsh-theme
xiong-chiamiov.zsh-theme

g-berthiaume avatar Nov 07 '23 14:11 g-berthiaume