dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit b220bb1e2d69a31169ca969d438580cee12697d1 (patch)
parent 3e246a919a2dc6d143af359bd1a1366389f41b75
Author: Alex Karle <alex@karle.co>
Date:   Mon, 18 Mar 2019 23:47:29 -0400

[bash] clean up prompt code a bit

Minor refactors, no major changes to the appearance, but the logic flows
a bit better IMO.

Diffstat:
Mbash/bash_prompt | 19++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git 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