Skip to content

Instantly share code, notes, and snippets.

@varenc
Last active June 1, 2021 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varenc/37e540568bb6ffafb00812a23ce9ebb8 to your computer and use it in GitHub Desktop.
Save varenc/37e540568bb6ffafb00812a23ce9ebb8 to your computer and use it in GitHub Desktop.
Turn off oh-my-zsh's git prompt info in certain directories (useful for networked/rclone mount filesystems/Dropbox/GDrive)
# Sometimes you don't want zsh/oh-my-zsh to show you the git status under certain paths
#
# For example, on a networked file systems (like Dropbox/GDrive or an rclone mount)
# oh-my-zsh's git prompt can slow things down. It calls `git` which then needs to
# look for a `.git` directory that probably doesn't exist. Sometimes this will force
# a query to the server so that the server can confirm that indeed, a `.git` directory
# does not exist in the current location. Or if it does it'll fetch all the contents
# (git also needs to check all your parent dirs for a `.git` folder as well...)
# Here's a simple solution. Put this where your other custimization are or just in `~/.zshrc`
function git_prompt_info_wrapper() {
# returns true if `/rclone_mount_filesystem/` is anywhere in your current path
if (
[[ $PWD/ = */rclone_mount_filesystem/* ]] ||
[[ $PWD/ = */Dropbox/* ]]
) ;
then
# uncomment these for help debugging
# (>&2 echo "skipping git status checks!")
else
# (>&2 echo "not skipping git status checks")
git_prompt_info;
fi
}
# Just replace `git_prompt_info` with `git_prompt_info_wrapper` in your PROMPT env
export PROMPT='${ret_status} %{$fg[cyan]%}%2d%{$reset_color%} $(git_prompt_info_wrapper)'
# if you don't define your own PROMPT and use the default, then you can get your current PROMPT
# by running `echo $PROMPT`. Or just paste in mine.
### TODO: Do something smarter instead of looking for a string in the path. Just check if the current dir is part of a mounted filesystem?
@henrywintif
Copy link

Thanks for this!

@varenc
Copy link
Author

varenc commented Jan 21, 2021

wow glad someone finally found this! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment