mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
vcs: separated concerns
This commit is contained in:
parent
8aeccc8d94
commit
a29f48070a
1 changed files with 42 additions and 27 deletions
69
zsh/prompt
69
zsh/prompt
|
|
@ -127,29 +127,46 @@ prompt_dir() {
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_git() {
|
prompt_git() {
|
||||||
local ref dirty wpath wname icon
|
|
||||||
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
if $(git rev-parse --is-inside-work-tree >/dev/null 2>&1); then
|
||||||
ref=$(git symbolic-ref HEAD 2> /dev/null)
|
PROMPT_VCS_TYPE='git'
|
||||||
wpath=$(cd $(dirname $(git rev-parse --git-dir)) && pwd)
|
PROMPT_VCS_REF=$(git symbolic-ref HEAD 2> /dev/null)
|
||||||
#wpath=$(cd . > /dev/null && pwd)
|
PROMPT_VCS_REF="${PROMPT_VCS_REF/refs\/heads\//}"
|
||||||
wname=$(basename $wpath)
|
PROMPT_VCS_WPATH=$(cd $(dirname $(git rev-parse --git-dir)) && pwd)
|
||||||
wpwd="${PWD#$wpath}"
|
PROMPT_VCS_WNAME=$(basename $PROMPT_VCS_WPATH)
|
||||||
prompt_segment green white $wname
|
PROMPT_VCS_WPWD="${PWD#$PROMPT_VCS_WPATH}"
|
||||||
if prompt_is_fancy; then
|
PROMPT_VCS_WPWD="${PROMPT_VCS_WPWD#/}"
|
||||||
branch_icon="$POWERLINE_BRANCH "
|
git diff --ignore-submodules --quiet
|
||||||
else
|
PROMPT_VCS_DIRTY=$?
|
||||||
branch_icon=""
|
|
||||||
fi
|
|
||||||
prompt_subsegment "${ref/refs\/heads\//$branch_icon}"
|
|
||||||
[[ -n $wpwd ]] && prompt_subsegment "${wpwd#/}"
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
|
unset PROMPT_VCS_TYPE
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_vcs_repo() {
|
prompt_vcs_repo() {
|
||||||
prompt_git
|
if prompt_git; then # TODO: || prompt_hg
|
||||||
|
local branch_icon repo_color
|
||||||
|
if prompt_is_fancy; then
|
||||||
|
branch_icon=" $POWERLINE_BRANCH "
|
||||||
|
else
|
||||||
|
branch_icon=" ⎇ "
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $PROMPT_VCS_DIRTY -eq 1 ]]; then
|
||||||
|
repo_color=yellow
|
||||||
|
else
|
||||||
|
repo_color=blue
|
||||||
|
fi
|
||||||
|
|
||||||
|
prompt_segment $repo_color white "$PROMPT_VCS_WNAME$branch_icon$PROMPT_VCS_REF"
|
||||||
|
[[ -n $PROMPT_VCS_WPWD ]] && prompt_segment green white "$PROMPT_VCS_WPWD"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_segment_test() {
|
prompt_segment_test() {
|
||||||
|
|
@ -196,17 +213,6 @@ rprompt_segment_test() {
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt_build() {
|
|
||||||
RPROMPT_SEGMENTS=''
|
|
||||||
prompt_setup_segments
|
|
||||||
CURRENT_BG='NONE'
|
|
||||||
prompt_host
|
|
||||||
#prompt_vcs_repo || prompt_dir
|
|
||||||
#prompt_vi_mode
|
|
||||||
prompt_end
|
|
||||||
echo -n ' '
|
|
||||||
}
|
|
||||||
|
|
||||||
prompt_last_rc() {
|
prompt_last_rc() {
|
||||||
#echo -n "%(?..%B[%?]%b)"
|
#echo -n "%(?..%B[%?]%b)"
|
||||||
[[ $LAST_CMD_RC -ne 0 ]] && prompt_segment red white "$LAST_CMD_RC"
|
[[ $LAST_CMD_RC -ne 0 ]] && prompt_segment red white "$LAST_CMD_RC"
|
||||||
|
|
@ -238,12 +244,21 @@ function zle-line-init zle-keymap-select {
|
||||||
zle -N zle-line-init
|
zle -N zle-line-init
|
||||||
zle -N zle-keymap-select
|
zle -N zle-keymap-select
|
||||||
|
|
||||||
|
prompt_build() {
|
||||||
|
RPROMPT_SEGMENTS=''
|
||||||
|
prompt_setup_segments
|
||||||
|
CURRENT_BG='NONE'
|
||||||
|
prompt_host
|
||||||
|
prompt_vcs_repo || prompt_dir
|
||||||
|
prompt_end
|
||||||
|
echo -n ' '
|
||||||
|
}
|
||||||
|
|
||||||
rprompt_build() {
|
rprompt_build() {
|
||||||
RPROMPT_SEGMENT=1
|
RPROMPT_SEGMENT=1
|
||||||
prompt_setup_segments
|
prompt_setup_segments
|
||||||
CURRENT_BG='NONE'
|
CURRENT_BG='NONE'
|
||||||
prompt_last_rc
|
prompt_last_rc
|
||||||
prompt_dir
|
|
||||||
rprompt_end
|
rprompt_end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue