Skip to content

Commit 3791923

Browse files
committed
zsh compatibility
1 parent b032b41 commit 3791923

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ Colorized:
9090
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\]\$ "
9191
```
9292

93+
#### ZSH
94+
95+
Add this to your `~/.zshrc`:
96+
97+
```zsh
98+
export GITAWAREPROMPT=~/.zsh/git-aware-prompt
99+
source "$GITAWAREPROMPT/main.sh"
100+
export PROMPT="%{$bldcyn%}%n@%m%{$txtrst%}:%{$txtgrn%}%~%{$bldpur%}\$git_branch%{$txtrst$txtylw%}\$git_dirty%{$txtrst%}$ "
101+
```
102+
93103
#### Windows
94104

95105
```bash

prompt.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ find_git_branch() {
1212
}
1313

1414
find_git_dirty() {
15-
local status=$(git status --porcelain 2> /dev/null)
16-
if [[ "$status" != "" ]]; then
15+
# In zsh "status" is a reserved word, so may not be used as a variable
16+
local _status=$(git status --porcelain 2> /dev/null)
17+
if [[ "$_status" != "" ]]; then
1718
git_dirty='*'
1819
else
1920
git_dirty=''
@@ -22,6 +23,14 @@ find_git_dirty() {
2223

2324
PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
2425

26+
# The above works for bash. For zsh we need this:
27+
if [[ -n "$ZSH_NAME" ]]; then
28+
setopt PROMPT_SUBST
29+
autoload add-zsh-hook
30+
add-zsh-hook precmd find_git_branch
31+
add-zsh-hook precmd find_git_dirty
32+
fi
33+
2534
# Default Git enabled prompt with dirty state
2635
# export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
2736

0 commit comments

Comments
 (0)