mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
bash prompt with segments (on par with zsh)
This commit is contained in:
parent
edd4797006
commit
c29d55e131
7 changed files with 205 additions and 176 deletions
81
zsh/prompt
81
zsh/prompt
|
|
@ -1,85 +1,26 @@
|
|||
source "$DOTFILES_SHELL_DIR/prompt_segments"
|
||||
source "$DOTFILES_ZSH_DIR/prompt_segments"
|
||||
source "$DOTFILES_SHELL_DIR/prompt_vcs"
|
||||
|
||||
prompt_host() {
|
||||
local bg='black'
|
||||
local fg='white'
|
||||
|
||||
if [[ $UID -eq 0 ]]; then
|
||||
prompt_segment red white '%n@%m'
|
||||
else
|
||||
prompt_segment black white '%n@%m'
|
||||
bg='red'
|
||||
fi
|
||||
|
||||
if [[ -n $SSH_CLIENT ]]; then
|
||||
fg='yellow'
|
||||
fi
|
||||
|
||||
prompt_segment $bg $fg '%n@%m'
|
||||
}
|
||||
|
||||
prompt_dir() {
|
||||
prompt_segment green white '%~'
|
||||
}
|
||||
|
||||
prompt_git() {
|
||||
if [[ -n $GIT_PS1_STATUS ]]; then
|
||||
PROMPT_VCS_TYPE='git'
|
||||
PROMPT_VCS_REF="$GIT_PS1_BRANCH"
|
||||
PROMPT_VCS_WPATH="$GIT_PS1_TOPLEVEL"
|
||||
PROMPT_VCS_WNAME="$GIT_PS1_NAME"
|
||||
PROMPT_VCS_WPWD="$GIT_PS1_PREFIX"
|
||||
[[ "$GIT_PS1_STATUS" == *t* ]] && PROMPT_VCS_DIRTY=1
|
||||
[[ "$GIT_PS1_STATUS" == *u* ]] && PROMPT_VCS_DIRTY=1
|
||||
[[ "$GIT_PS1_STATUS" == *s* ]] && PROMPT_VCS_DIRTY=1
|
||||
return 0
|
||||
else
|
||||
unset PROMPT_VCS_TYPE
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_vcs_repo() {
|
||||
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=red
|
||||
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_vcs_status() {
|
||||
# status symbols
|
||||
if prompt_git; then
|
||||
local vcs_status=""
|
||||
[[ "$GIT_PS1_STATUS" == *h* ]] && vcs_status+="${NONE}↰"
|
||||
[[ "$GIT_PS1_STATUS" == *t* ]] && vcs_status+="${R}!"
|
||||
[[ "$GIT_PS1_STATUS" == *u* ]] && vcs_status+="${Y}≠"
|
||||
[[ "$GIT_PS1_STATUS" == *s* ]] && vcs_status+="${R}±"
|
||||
[[ "$GIT_PS1_STATUS" == *n* ]] && vcs_status+="${BB}∅"
|
||||
[[ -n "$vcs_status" ]] && prompt_segment black white "${vcs_status}"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_vcs_action() {
|
||||
# action info
|
||||
if prompt_git; then
|
||||
local action=""
|
||||
[[ "$GIT_PS1_STATUS" == *R* ]] && action+=" rebase"
|
||||
[[ "$GIT_PS1_STATUS" == *i* ]] && action+="-i"
|
||||
[[ "$GIT_PS1_STATUS" == *A* ]] && action+=" apply"
|
||||
[[ "$GIT_PS1_STATUS" == *M* ]] && action+=" merge"
|
||||
[[ "$GIT_PS1_STATUS" == *B* ]] && action+=" bisect"
|
||||
[[ -n "$action" ]] && prompt_segment red white "$action"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_segment_test() {
|
||||
prompt_segment red white
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue