A bash prompt that includes battery level & git branch Is there a better way to handle the color codes and display git branch and battery percentage?

#!/bin/bash

## set colors
t="\[\033[0;34m\]"
p="\[\033[0;35m\]"
g="\[\033[0;32m\]"
b="\[\033[0;36m\]"
y="\[\033[0;33m\]"
## the color reset code
re="\[\033[0m\]"



## inserts git brance into prompt at $(PBG)
PBG(){
    git branch 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}


I would rather not make three different calls to insert the battery level.

## inserts battery percentage into prompt @ $(BATT)
BATT(){
    acpi | awk '{print $4}' | sed -e 's/,//'
}

PS1="$b($re$y\$(BATT)$re$p \h$re $gÎ»$re $g\W$re$t \$(PBG)$re$b)$re "
Since the prompt is dynamic, executed after every command you enter in the shell, it's important to make it as fast as possible.
For example, reduce the number of processes executed as much as possible.

Instead of git branch + sed, there is an idiomatic way to get the name of the current branch using git rev-parse:

git rev-parse --abbrev-ref HEAD


That's one process instead of two.

And to get the battery percentage,
you could replace the awk + sed with a single awk:

awk '{ sub(",", "", $4); print $4 }'


I don't what is the output of the acpi command,
but I would try to extract from it the relevant part using the Pattern substitution feature of Bash itself.
That would eliminate all external processes, for best performance.