From ec10088321b63616397cf0774393e99c10b745d2 Mon Sep 17 00:00:00 2001 From: Steven Proctor Date: Mon, 1 Oct 2012 17:09:27 -0500 Subject: [PATCH] updated to have prompt refreshed on each new prompt --- .bash_profile | 2 +- .bashrc | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .bashrc diff --git a/.bash_profile b/.bash_profile index a39ecf7..e612dcf 100644 --- a/.bash_profile +++ b/.bash_profile @@ -31,5 +31,5 @@ battery_status() fi } -PS1="$(battery_status) \h:\W \u\$ " +export PROMPT_COMMAND='PS1="$(battery_status) \h:\W \u\$ "' diff --git a/.bashrc b/.bashrc new file mode 100644 index 0000000..60d39bf --- /dev/null +++ b/.bashrc @@ -0,0 +1,28 @@ +# came from Aaron Lasseigne (AaronLasseigne on GitHub) +battery_status() +{ + HEART='♥ ' + + NON='\[\e[0m\]' + RED='\[\e[0;31m\]' + + battery_info=`ioreg -rc AppleSmartBattery` + current_charge=$(echo $battery_info | grep -o '"CurrentCapacity" = [0-9]\+' | cut -d ' ' -f 3) + total_charge=$(echo $battery_info | grep -o '"MaxCapacity" = [0-9]\+' | cut -d ' ' -f 3) + + charged_slots=$(echo "(($current_charge/$total_charge)*10)+1" | bc -l | cut -d '.' -f 1) + if [[ $charged_slots -gt 10 ]]; then + charged_slots=10 + fi + + echo -n "${RED}" + for i in `seq 1 $charged_slots`; do echo -n "$HEART"; done + echo -n "${NON}" + + if [[ $charged_slots -lt 10 ]]; then + for i in `seq 1 $(echo "10-$charged_slots" | bc)`; do echo -n "$HEART"; done + fi +} + +PS1="$(battery_status) \h:\W \u\$ " +