From b220bb1e2d69a31169ca969d438580cee12697d1 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Mon, 18 Mar 2019 23:47:29 -0400 Subject: [PATCH] [bash] clean up prompt code a bit Minor refactors, no major changes to the appearance, but the logic flows a bit better IMO. --- bash/bash_prompt | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/bash/bash_prompt b/bash/bash_prompt index 60eca7f..a37dc99 100644 --- a/bash/bash_prompt +++ b/bash/bash_prompt @@ -14,8 +14,6 @@ fi if [ -n "$SSH_CLIENT" ]; then ssh_text="[$USER@$(hostname)] " -else - ssh_text="" fi function parse_git_dirty() { @@ -26,9 +24,10 @@ function parse_git_branch() { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" } -# get colors from tput (else hardcode them) +# Preferred Prompt: Fancy with colors from tput if tput setaf 1 &> /dev/null; then tput sgr0 if [[ $(tput colors) -ge 16 ]] 2>/dev/null; then + SET_PREFERRED_PROMPT=1 MAGENTA="\[$(tput setaf 5)\]" ORANGE="\[$(tput setaf 11)\]" GRAY="\[$(tput setaf 8)\]" @@ -37,15 +36,13 @@ if tput setaf 1 &> /dev/null; then tput sgr0 RESET="\[$(tput sgr0)\]" export PS1="$BOLD$BLUE\w $RESET$GRAY${ssh_text}\$(parse_git_branch)"$'\n'"$BOLD$MAGENTA\$ $RESET" - export PS2="$ORANGE→ $RESET" - else - # TODO: write better case for too few colors... - export PS1="\w\n\$ " - export PS2="> " + export PS2="$ORANGE> $RESET" fi -else - # TODO: write better case for no tput... - export PS1="\w\n\$ " +fi + +# Fallback Option: No colors, No Git +if [ -z $SET_PREFERRED_PROMPT ]; then + export PS1="\w\n${ssh_text}\$ " export PS2="> " fi -- libgit2 0.28.4