I don't have a Mac, so I can't actually properly test this, but I've looked around online for example output using that command, so this is the best I can do with it. This saves using extra processes when bash is more than capable of doing it itself.
Because I'm using a while read array, the "(no" and "not" testing will probably be broken, but will be easy to sort; I just can't test for that condition, sadly.
This also compresses it and makes it more concise. Feel free to go with the more stretched out styling of this, but thought I would show my approach. :)
while read -a X; do
time_left="${X[9]}"
done <<< `pmset -g batt`
[[ "$(pmset -g ac)" == *"No adapter attached."* ]] && emoji='🔋' || emoji='🔌'
case "$time_left" in
\(no|not) time_left='⌛️ ' ;;
0:00) time_left='⚡️ ' ;;
esac
printf "\033[1;92m$emoji $time_left \033[0m"
Hi,
Hope this helps. It's regarding:
https://github.com/holman/dotfiles/blob/master/bin/battery-status
I don't have a Mac, so I can't actually properly test this, but I've looked around online for example output using that command, so this is the best I can do with it. This saves using extra processes when bash is more than capable of doing it itself.
Because I'm using a while read array, the "(no" and "not" testing will probably be broken, but will be easy to sort; I just can't test for that condition, sadly.
This also compresses it and makes it more concise. Feel free to go with the more stretched out styling of this, but thought I would show my approach. :)