olivierverdier / zsh-git-prompt

Informative git prompt for zsh
MIT License
1.71k stars 394 forks source link

Example of ~/.zshrc #141

Open LDAmorim opened 4 years ago

LDAmorim commented 4 years ago

Hi,

I only learned about your project recently and already find it really useful!

I am not sure if this is the best place for me to share this or if it is important, so feel free to delete this issue.

I just thought an "example" configuration could help people save some time looking for this. The system I tested this in is a macOS Catalina.

Please feel free to let me know if there is a better way to implement this example.

Thank you for this repo, Diana


Example

So that whenever I switch to a new folder it tests if it is a git repo and if it is calls the PROMPT option, if not keeps it a zsh shell. I added the example lines below to ~/.zshrc

function chpwd {
TEST_git=$(git rev-parse --is-inside-work-tree) 2>/dev/null
if [ "$TEST_git" = "true" ]; then
      pwd
      source /Users/LDianaAmorim/Documents/opt/zsh-git-prompt/zshrc.sh
      # an example prompt
      PROMPT='%B%m%~%b$(git_super_status) %# '
else
      exec zsh
fi
}

I had to create that file (before I only had ~/.zprofile) and decided not to use the .sh termination as is consistent with other profile files.

iamalexaz commented 4 years ago

can i ask how to fix git super status error?

LDAmorim commented 4 years ago

Hi! Could you please share the error message?

craftyguy commented 3 years ago

invoking git every time might be kinda slow, it's faster to do something like [ -d .git ]. It's probably(?) unlikely there would be a .git directory in pwd that is not a git repo :)

thomasrebele commented 3 years ago

@craftyguy, the git directory exists only at the root of the git repository. The check would need to look recursively at the parent directories as well.

If you want a faster git prompt, you could try https://github.com/zsh-git-prompt/zsh-git-prompt/. It uses the shell directly, avoiding the startup cost of Python or Haskell.

craftyguy commented 3 years ago

@craftyguy, the git directory exists only at the root of the git repository. The check would need to look recursively at the parent directories as well.

If you want a faster git prompt, you could try https://github.com/zsh-git-prompt/zsh-git-prompt/. It uses the shell directly, avoiding the startup cost of Python or Haskell.

ah yes, good point.