Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow prompt command (oh-my-zsh) #1

Open
ofenerci opened this issue Apr 3, 2019 · 18 comments
Open

Slow prompt command (oh-my-zsh) #1

ofenerci opened this issue Apr 3, 2019 · 18 comments

Comments

@ofenerci
Copy link

ofenerci commented Apr 3, 2019

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?

@hsab
Copy link
Owner

hsab commented Apr 3, 2019

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
Copy link
Owner

hsab commented Apr 3, 2019

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

@mp3por
Copy link

mp3por commented Jan 20, 2020

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

@johndbell
Copy link

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

@Redshoee
Copy link

same issue with @mp3por

@cloverhearts
Copy link

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

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

@victor-borges
Copy link

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.

@CompSciMaj13
Copy link

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

@trallnag
Copy link

trallnag commented Sep 19, 2021

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.

@andywatts
Copy link

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

@scardenasb
Copy link

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.

@ShinJustinHolly3317
Copy link

@scardenasb
That's the real reason

@ethanchanus
Copy link

ethanchanus commented Feb 24, 2023

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

@b-hayes
Copy link

b-hayes commented Jun 24, 2023

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?

@Hobart2967
Copy link

Hobart2967 commented Jun 27, 2023

@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: Hobart2967/shell-setup@291fcb5

@b-hayes
Copy link

b-hayes commented Jul 8, 2023

@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

@jnguyen1098
Copy link

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

@g-berthiaume
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests