1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- autoload -U colors && colors
- setopt promptsubst
- setopt promptpercent
- local time='%F{cyan}%B[%D{%H:%M}]%b%f'
- local user='%F{yellow}%B%n%b%f'
- local host='%F{blue}%B%M%b%f'
- local dir='%F{yellow}%~%f'
- local git='$(git_prompt_string)'
- local error='%F{red}%B%(?..%?)%b%f'
- PROMPT="$time $user@$host $dir $git%# "
- RPROMPT="$error"
- # Show Git branch/tag, or name-rev if on detached head
- parse_git_branch() {
- (git symbolic-ref -q HEAD || git rev-parse --short HEAD) 2> /dev/null
- }
- # Show different symbols as appropriate for various Git repository states
- parse_git_state() {
- # Compose this value via multiple conditional appends.
- local GIT_STATE=""
- local GIT_CHANGED="$(git diff --name-only --diff-filter=ACDMRT | wc -l | tr -d ' ')"
- local GIT_STAGED="$(git diff --staged --name-status --diff-filter=ACDMRT | wc -l | tr -d ' ')"
- local GIT_CONFLICTS="$(git diff --staged --name-status --diff-filter=U | wc -l | tr -d ' ')"
- local GIT_UNTRACKED="$(git ls-files --other --exclude-standard | wc -l | tr -d ' ')"
- if [ $GIT_STAGED -ne 0 ]; then
- GIT_STATE="$GIT_STATE%F{green}+$GIT_STAGED%f"
- fi
- if [ $GIT_CONFLICTS -ne 0 ]; then
- GIT_STATE="$GIT_STATE%F{red}x$GIT_CONFLICTS%f"
- fi
- if [ $GIT_CHANGED -ne 0 ]; then
- GIT_STATE="$GIT_STATE%F{red}*$GIT_CHANGED%f"
- fi
- if [ $GIT_UNTRACKED -ne 0 ]; then
- GIT_STATE="$GIT_STATE.."
- fi
- if [ $GIT_CHANGED -eq 0 -a $GIT_STAGED -eq 0 -a $GIT_CONFLICTS -eq 0 -a $GIT_UNTRACKED -eq 0 ]; then
- GIT_STATE="$GIT_STATE%B%F{green}ok%f%b"
- fi
- if [[ -n $GIT_STATE ]]; then
- echo $GIT_STATE
- fi
- }
- # If inside a Git repository, print its branch and state
- git_prompt_string() {
- local git_where="$(parse_git_branch)"
- if [ -n "$git_where" ]; then
- git_where="%B%F{magenta}${git_where#(refs/heads/|tags/)}%f%b"
- local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
- if [ "$NUM_AHEAD" -gt 0 ]; then
- git_where="$git_where^$NUM_AHEAD"
- fi
- local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
- if [ "$NUM_BEHIND" -gt 0 ]; then
- git_where=$git_where"v$NUM_BEHIND"
- fi
- echo "($git_where|$(parse_git_state))"
- fi
- }
|