Skip to content

Commit

Permalink
zsh compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
joeytwiddle committed Aug 9, 2021
1 parent b032b41 commit 3791923
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
export GITAWAREPROMPT=~/.zsh/git-aware-prompt
source "$GITAWAREPROMPT/main.sh"
export PROMPT="%{$bldcyn%}%n@%m%{$txtrst%}:%{$txtgrn%}%~%{$bldpur%}\$git_branch%{$txtrst$txtylw%}\$git_dirty%{$txtrst%}$ "
```

#### Windows

```bash
Expand Down
13 changes: 11 additions & 2 deletions prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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, so may not be used as a variable
local _status=$(git status --porcelain 2> /dev/null)
if [[ "$_status" != "" ]]; then
git_dirty='*'
else
git_dirty=''
Expand All @@ -22,6 +23,14 @@ 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\]\$ "

Expand Down

0 comments on commit 3791923

Please sign in to comment.