From f8537320d4f628e73e2525882a5dbe630020276c Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Thu, 4 Dec 2014 16:08:22 +0100 Subject: [PATCH] ported simple zsh prompt to bash --- bash/prompt | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/bash/prompt b/bash/prompt index cdc26af..0ae04cc 100644 --- a/bash/prompt +++ b/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