diff --git a/README.md b/README.md index b6b25ed..33e0483 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,16 @@ Colorized: export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ " ``` +#### ZSH + +Add this to your `~/.zshrc`: + +```zsh +source ~/git-aware-prompt/main.sh +source ~/git-aware-prompt/colors.sh +export PROMPT='%{$bldred%}%n@%m%{$txtrst%}:%{$bldgrn%}%~%{$bldpur%}$git_branch%{$txtrst$txtylw%}$git_dirty%{$txtrst%}$ ' +``` + #### Windows ```bash diff --git a/prompt.sh b/prompt.sh index 6a737b8..c3e7368 100644 --- a/prompt.sh +++ b/prompt.sh @@ -12,8 +12,9 @@ find_git_branch() { } find_git_dirty() { - local status=$(git status --porcelain 2> /dev/null) - if [[ "$status" != "" ]]; then + # In zsh "status" is a reserved word + local _status=$(git status --porcelain 2> /dev/null) + if [[ "$_status" != "" ]]; then git_dirty='*' else git_dirty='' @@ -22,6 +23,15 @@ find_git_dirty() { PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND" +# The above works for bash. For zsh we need this: +if [[ -n "$ZSH_NAME" ]]; then + setopt PROMPT_SUBST + + autoload add-zsh-hook + add-zsh-hook precmd find_git_branch + add-zsh-hook precmd find_git_dirty +fi + # Default Git enabled prompt with dirty state # export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "