all repos — dotfiles @ 7c2bd86a4dfe09222865e5e11f5790d211bc13c5

my *nix dotfiles

home/bin/bat (view raw)

 1#!/usr/bin/env bash
 2
 3if [[ "$(uname)" == "Darwin" ]]; then
 4    cap="$(pmset -g batt | grep -Eo "\d+%" | cut -d% -f1)"
 5    is_charging=""
 6else
 7    cap="$(apm -l)"
 8    is_charging="$(apm -a)"
 9
10    status="discharging"
11fi
12
13tmux_bat() {
14    if [[ "$is_charging" -eq 1 ]]; then 
15        printf '%s%%' "+$cap"
16    else
17        printf '%s%%' "$cap"
18    fi
19}
20
21if [[ "$1" == "-q" ]]; then
22   tmux_bat 
23else
24    [[ "$is_charging" -eq 1 ]] &&
25        status="charging"
26    printf '%s%% [%s]\n' $cap $status 
27fi