mirror of
https://github.com/lloeki/dotfiles.git
synced 2025-12-06 07:24:39 +01:00
ported simple zsh prompt to bash
This commit is contained in:
parent
5c386aa52d
commit
f8537320d4
1 changed files with 51 additions and 3 deletions
54
bash/prompt
54
bash/prompt
|
|
@ -40,7 +40,55 @@ prompt_last_rc() {
|
|||
[[ $LAST_CMD_RC -ne 0 ]] && prompt_segment red white "$LAST_CMD_RC"
|
||||
}
|
||||
|
||||
set_prompt() {
|
||||
__git_ps1_vars
|
||||
PS1="$(prompt_build)"
|
||||
function contains() {
|
||||
[[ "$2" == *$1* ]]
|
||||
}
|
||||
|
||||
function prompt_pwd() {
|
||||
if [[ $PWD == $HOME ]]; then
|
||||
echo -n "~"
|
||||
else
|
||||
echo -n "${PWD##*/}"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_build_simple() {
|
||||
__git_ps1_vars
|
||||
|
||||
set_color -p green
|
||||
prompt_pwd
|
||||
|
||||
# add git prompt info
|
||||
if [[ -n "$GIT_PS1_STATUS" ]]; then
|
||||
set_color -p blue
|
||||
echo -n " $GIT_PS1_BRANCH"
|
||||
|
||||
vcs_status=""
|
||||
contains h "$GIT_PS1_STATUS" && vcs_status="$vcs_status""↰"
|
||||
contains t "$GIT_PS1_STATUS" && vcs_status="$vcs_status""!"
|
||||
contains u "$GIT_PS1_STATUS" && vcs_status="$vcs_status""≠"
|
||||
contains s "$GIT_PS1_STATUS" && vcs_status="$vcs_status""±"
|
||||
contains n "$GIT_PS1_STATUS" && vcs_status="$vcs_status""∅"
|
||||
set_color -p red
|
||||
[[ -n "$vcs_status" ]] && echo -n " $vcs_status"
|
||||
|
||||
action=""
|
||||
contains R "$GIT_PS1_STATUS" && action="$action rebase"
|
||||
contains i "$GIT_PS1_STATUS" && action="$action-i"
|
||||
contains A "$GIT_PS1_STATUS" && action="$action apply"
|
||||
contains M "$GIT_PS1_STATUS" && action="$action merge"
|
||||
contains B "$GIT_PS1_STATUS" && action="$action bisect"
|
||||
set_color -p yellow
|
||||
[[ -n "$action" ]] && echo -n "$action"
|
||||
fi
|
||||
|
||||
# close prompt
|
||||
set_color -p none
|
||||
echo -n '> '
|
||||
}
|
||||
|
||||
set_prompt() {
|
||||
PS1="$(prompt_build_simple)"
|
||||
}
|
||||
|
||||
# vim: ft=sh
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue