diff options
author | Mattias Andrée <maandree@kth.se> | 2023-11-18 23:23:40 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-11-18 23:23:40 +0100 |
commit | 0f1df0db903ba576fd17b08197d3066af7a61e5f (patch) | |
tree | a59c04307b1382257afa3c3512ec3abadf7e0e47 /bash/bashrc_prompt | |
parent | Use losetup -d instead of --detach and add clean up (diff) | |
download | dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.gz dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.bz2 dotfiles-0f1df0db903ba576fd17b08197d3066af7a61e5f.tar.xz |
A lot of changes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-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 |