Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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