Add git branch to zsh prompt
This commit is contained in:
parent
ffe8a0e79e
commit
5e6ce927a1
1 changed files with 8 additions and 1 deletions
|
|
@ -40,15 +40,22 @@ else
|
||||||
local gray="%{$fg[white]%}"
|
local gray="%{$fg[white]%}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
function parse_git_branch {
|
||||||
|
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
|
||||||
|
echo "${colon}${orange}${ref#refs/heads/}%f"
|
||||||
|
}
|
||||||
|
|
||||||
local lbrkt="${gray}[%f"
|
local lbrkt="${gray}[%f"
|
||||||
local rbrkt="${gray}]%f"
|
local rbrkt="${gray}]%f"
|
||||||
local colon="${gray}:%f"
|
local colon="${gray}:%f"
|
||||||
local user="${purple}%n%f"
|
local user="${purple}%n%f"
|
||||||
local host="${blue}%m%f"
|
local host="${blue}%m%f"
|
||||||
local dir="${green}%~%f"
|
local dir="${green}%~%f"
|
||||||
|
local branch="\$(parse_git_branch)"
|
||||||
|
|
||||||
|
setopt prompt_subst
|
||||||
export PROMPT="%# "
|
export PROMPT="%# "
|
||||||
export RPROMPT="${lbrkt}${user}${colon}${host}${colon}${dir}${rbrkt}"
|
export RPROMPT="${lbrkt}${user}${colon}${host}${colon}${dir}${branch}${rbrkt}"
|
||||||
|
|
||||||
# aliases
|
# aliases
|
||||||
source $HOME/.config/zsh/aliases
|
source $HOME/.config/zsh/aliases
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue