diff options
Diffstat (limited to 'bash/bashrc_prompt')
-rw-r--r-- | bash/bashrc_prompt | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/bash/bashrc_prompt b/bash/bashrc_prompt index 5463afb..dc0e920 100644 --- a/bash/bashrc_prompt +++ b/bash/bashrc_prompt @@ -153,13 +153,15 @@ git-colour () { __prompt_func_git () { - exec 2>/dev/null - if git status >&2; then - status="$(git status -s -b | head -n 1)" - if [ "$(echo "${status}" | cut -d ' ' -f 3)" = '[ahead' ]; then - echo "${status}" | cut -d ' ' -f 2 + if __prompt_func_git_branch="$(LANG=C git branch --format='%(if)%(HEAD)%(then)%(refname:short)%(end)' 2>/dev/null)"; then + if __prompt_func_git_branch="$(printf '%s\n' "${__prompt_func_git_branch}" | grep -v '^$')"; then + if [ -z "${__prompt_func_git_branch}" ]; then + printf '%s' '(orphan)' + else + printf '%s' "${__prompt_func_git_branch}" | sed 's/^(HEAD detached at .*)$/(detached)/' + fi else - echo "${status}" | cut -d ' ' -f 2 | cut -d . -f 1 + printf '%s' '(orphan)' fi fi } @@ -368,7 +370,7 @@ update-prompt () { fi if [ "${__prompt_git}" = "1" ]; then if [ ! "${PS1}" = "" ]; then - PS1="${PS1}"'$(git status 2>/dev/null >&2 && echo -n : || echo -n "")' + PS1="${PS1}"'$(if git branch 2>/dev/null >&2; then printf ':'; fi)' fi PS1="${PS1}\[\033[${__prompt_git_colour}m\]"'$(__prompt_func_git)'"\[\033[00m\]" fi |