refactor(zsh): extract prompt functions
This commit is contained in:
parent
436c3d4b1f
commit
8ed8b71a7e
|
@ -1,15 +1,34 @@
|
|||
setopt prompt_subst
|
||||
autoload -Uz colors && colors
|
||||
|
||||
git_branch() {
|
||||
prompt_color() {
|
||||
[[ -n "$1" ]] && print "%{$fg_bold[$2]%}$1%{$reset_color%}"
|
||||
}
|
||||
|
||||
prompt_blue() { print "$(prompt_color "$1" blue)" }
|
||||
prompt_green() { print "$(prompt_color "$1" green)" }
|
||||
prompt_red() { print "$(prompt_color "$1" red)" }
|
||||
prompt_yellow() { print "$(prompt_color "$1" yellow)" }
|
||||
|
||||
prompt_full_path() {
|
||||
print "$(prompt_blue %~)"
|
||||
}
|
||||
|
||||
prompt_shortened_path() {
|
||||
print "$(prompt_blue %2~)"
|
||||
}
|
||||
|
||||
prompt_git_branch() {
|
||||
local branch="$(git symbolic-ref HEAD 2> /dev/null | cut -d'/' -f3)"
|
||||
|
||||
[ -n "${branch}" ] && echo " ${branch}"
|
||||
[ -n "${branch}" ] && print "$(prompt_green $branch)"
|
||||
}
|
||||
|
||||
git_commit() {
|
||||
prompt_git_commit() {
|
||||
local commit_sha="$(git rev-parse --short HEAD 2> /dev/null)"
|
||||
|
||||
[ -n "${commit_sha}" ] && echo " [%{$fg[yellow]%}${commit_sha}%{$reset_color%}]"
|
||||
[ -n "${commit_sha}" ] && echo [$(prompt_yellow $commit_sha)]
|
||||
}
|
||||
|
||||
export PS1='%{$fg[blue]%}%~%{$reset_color%}%{$fg[green]%}$(git_branch)%{$reset_color%}$(git_commit) $ '
|
||||
setopt prompt_subst
|
||||
|
||||
PROMPT='$(prompt_shortened_path) $(prompt_git_branch) $(prompt_git_commit) $ '
|
||||
|
|
Loading…
Reference in a new issue