git branch parsing
This commit is contained in:
parent
c9f191bf49
commit
26b9cdf1b9
30
zsh/colors
30
zsh/colors
@ -5,12 +5,38 @@ alias ls='ls --color=auto --group-directories-first'
|
|||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
|
PS1__GET_DIRECTORY() {
|
||||||
|
local _DIRECTORY="%B%F{yellow}%6~"
|
||||||
|
local GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
|
||||||
|
[ $GIT_ROOT ] && {
|
||||||
|
local PROJECT_NAME=$(basename $GIT_ROOT)
|
||||||
|
[[ $PROJECT_NAME =~ code ]] && PROJECT_NAME=$(basename $(dirname $GIT_ROOT))
|
||||||
|
|
||||||
|
local RELATIVE_DIRECTORY=${${PWD#$GIT_ROOT}:1}
|
||||||
|
[[ ${#${RELATIVE_DIRECTORY//[^\/]}} -gt 3 ]] && RELATIVE_DIRECTORY='*/%4~'
|
||||||
|
|
||||||
|
_DIRECTORY="%B%F{green}$PROJECT_NAME%B%F{yellow}:$RELATIVE_DIRECTORY"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $_DIRECTORY
|
||||||
|
}
|
||||||
|
|
||||||
|
PS1__GET_GIT_BRANCH() {
|
||||||
|
local _GIT_BRANCH=$(\
|
||||||
|
git branch --no-color 2>/dev/null \
|
||||||
|
| sed "/^[^*]/d; s/* \(.*\)/ %B%F{cyan}$PS1_BRANCH_SYMBOL \1/" \
|
||||||
|
)
|
||||||
|
|
||||||
|
echo $_GIT_BRANCH
|
||||||
|
}
|
||||||
|
|
||||||
GENERATE_PS1() {
|
GENERATE_PS1() {
|
||||||
|
|
||||||
local _INDICATOR="%B%(?.%F{green}.%F{red}) $PS1_INDICATOR_SYMBOL"
|
local _INDICATOR="%B%(?.%F{green}.%F{red}) $PS1_INDICATOR_SYMBOL"
|
||||||
local _USER="%B%F{magenta}$PS1_USER"
|
local _USER="%B%F{magenta}$PS1_USER"
|
||||||
local _SEPARATOR="%b%F{red}$PS1_SEPARATOR"
|
local _SEPARATOR="%b%F{red}$PS1_SEPARATOR"
|
||||||
local _DIRECTORY='%B%F{yellow}%6~'
|
local _DIRECTORY='$(PS1__GET_DIRECTORY)'
|
||||||
local _GIT_BRANCH='%B%F{cyan} $(git branch --no-color 2>/dev/null | sed "/^[^*]/d; s/* \(.*\)/$PS1_BRANCH_SYMBOL \1/")'
|
local _GIT_BRANCH='$(PS1__GET_GIT_BRANCH)'
|
||||||
|
|
||||||
local _PROMPT=$'\n'' %B%F{blue}%# %b%f'
|
local _PROMPT=$'\n'' %B%F{blue}%# %b%f'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user