dotfiles

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

commit 7e73cfc9c57bd60374ba626a7fe56a242df4efd9 (patch)
parent 2657b88d4b57c6501abb0a5260ec60c0fd2f2db9
Author: Alex Karle <alex@alexkarle.com>
Date:   Tue, 23 Feb 2021 14:22:51 -0500

bash: Add non-colored backup "pretty prompt", simplify git-stuff

This patch adds a non-colored version of the "pretty prompt" if
tput is failing (i.e. on OpenBSD).

git branch --show-current has been in git since this commit [1]
(2.22, 2.5 years now), and is a much simpler alternative to parsing
git-branch's output with sed.

[1]: 0ecb1fc7269e15be890870937b8b639c987abd08

Diffstat:
M.bashrc | 21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/.bashrc b/.bashrc @@ -31,23 +31,22 @@ PROMPT_COMMAND="history -a" # Record history after each command if [ -n "$PRETTY_COLORS" ]; then # ls colors - if ls --color >/dev/null 2>&1; then - alias ls='ls --color' - elif ls -G >/dev/null 2>&1; then - alias ls='ls -G' - elif colorls -G >/dev/null 2>&1; then - alias ls='colorls -G' + if ls --color &>/dev/null; then + alias ls='ls --color' + elif ls -G &>/dev/null; then + alias ls='ls -G' + elif colorls -G &>/dev/null; then + alias ls='colorls -G' fi parse_git_dirty() { if [ -z "$BASH_PROMPT_NO_GSTATUS" ]; then - [ "$(git status --porcelain=v1 2> /dev/null)" ] && echo "*" + [ -n "$(git status --porcelain=v1 2>/dev/null)" ] && echo "*" fi } git_info() { - git branch --no-color 2> /dev/null | - sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" + echo "$(git branch --show-current 2>/dev/null)$(parse_git_dirty)" } # Preferred Prompt: fancy with colors from tput @@ -61,9 +60,11 @@ if [ -n "$PRETTY_COLORS" ]; then BOLD="\[$(tput bold)\]" RESET="\[$(tput sgr0)\]" - PS1_TOP="$BOLD$RED\$(last_err)$BLUE\w $RESET$GRAY$SSH_PROMPT\$(git_info)" + PS1_TOP="$BOLD$RED\$(last_err)$BLUE\w $RESET$GRAY\$(git_info) [\u@\h]" PS1="$PS1_TOP\n$BOLD$MAGENTA\$ $RESET" PS2="$YELLOW> $RESET" + else + PS1="\$(last_err)\w \$(git_info) [\u@\h]\n\$ " fi fi