Populate repo
This commit is contained in:
23
tmux/.tmux/plugins/tmux-battery/scripts/battery_color.sh
Executable file
23
tmux/.tmux/plugins/tmux-battery/scripts/battery_color.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_color() {
|
||||
local plane="$1"
|
||||
local status="$2"
|
||||
if [ "$status" == "discharging" ]; then
|
||||
$CURRENT_DIR/battery_color_charge.sh "$plane"
|
||||
else
|
||||
$CURRENT_DIR/battery_color_status.sh "$plane" "$status"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local status="$(battery_status)"
|
||||
local plane="$1"
|
||||
print_color "$plane" "$status"
|
||||
}
|
||||
|
||||
main $@
|
98
tmux/.tmux/plugins/tmux-battery/scripts/battery_color_charge.sh
Executable file
98
tmux/.tmux/plugins/tmux-battery/scripts/battery_color_charge.sh
Executable file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
color_charge_primary_tier8=''
|
||||
color_charge_primary_tier7=''
|
||||
color_charge_primary_tier6=''
|
||||
color_charge_primary_tier5=''
|
||||
color_charge_primary_tier4=''
|
||||
color_charge_primary_tier3=''
|
||||
color_charge_primary_tier2=''
|
||||
color_charge_primary_tier1=''
|
||||
color_charge_secondary_tier8=''
|
||||
color_charge_secondary_tier7=''
|
||||
color_charge_secondary_tier6=''
|
||||
color_charge_secondary_tier5=''
|
||||
color_charge_secondary_tier4=''
|
||||
color_charge_secondary_tier3=''
|
||||
color_charge_secondary_tier2=''
|
||||
color_charge_secondary_tier1=''
|
||||
|
||||
# script default variables
|
||||
color_charge_primary_tier8_default='#00ff00'
|
||||
color_charge_primary_tier7_default='#55ff00'
|
||||
color_charge_primary_tier6_default='#aaff00'
|
||||
color_charge_primary_tier5_default='#ffff00'
|
||||
color_charge_primary_tier4_default='#ffc000'
|
||||
color_charge_primary_tier3_default='#ff8000'
|
||||
color_charge_primary_tier2_default='#ff4000'
|
||||
color_charge_primary_tier1_default='#ff0000'
|
||||
color_charge_secondary_tier8_default='colour0'
|
||||
color_charge_secondary_tier7_default='colour0'
|
||||
color_charge_secondary_tier6_default='colour0'
|
||||
color_charge_secondary_tier5_default='colour0'
|
||||
color_charge_secondary_tier4_default='colour0'
|
||||
color_charge_secondary_tier3_default='colour0'
|
||||
color_charge_secondary_tier2_default='colour0'
|
||||
color_charge_secondary_tier1_default='colour0'
|
||||
|
||||
# colors are set as script global variables
|
||||
get_color_charge_settings() {
|
||||
color_charge_primary_tier8=$(get_tmux_option "@batt_color_charge_primary_tier8" "$color_charge_primary_tier8_default")
|
||||
color_charge_primary_tier7=$(get_tmux_option "@batt_color_charge_primary_tier7" "$color_charge_primary_tier7_default")
|
||||
color_charge_primary_tier6=$(get_tmux_option "@batt_color_charge_primary_tier6" "$color_charge_primary_tier6_default")
|
||||
color_charge_primary_tier5=$(get_tmux_option "@batt_color_charge_primary_tier5" "$color_charge_primary_tier5_default")
|
||||
color_charge_primary_tier4=$(get_tmux_option "@batt_color_charge_primary_tier4" "$color_charge_primary_tier4_default")
|
||||
color_charge_primary_tier3=$(get_tmux_option "@batt_color_charge_primary_tier3" "$color_charge_primary_tier3_default")
|
||||
color_charge_primary_tier2=$(get_tmux_option "@batt_color_charge_primary_tier2" "$color_charge_primary_tier2_default")
|
||||
color_charge_primary_tier1=$(get_tmux_option "@batt_color_charge_primary_tier1" "$color_charge_primary_tier1_default")
|
||||
color_charge_secondary_tier8=$(get_tmux_option "@batt_color_charge_secondary_tier8" "$color_charge_secondary_tier8_default")
|
||||
color_charge_secondary_tier7=$(get_tmux_option "@batt_color_charge_secondary_tier7" "$color_charge_secondary_tier7_default")
|
||||
color_charge_secondary_tier6=$(get_tmux_option "@batt_color_charge_secondary_tier6" "$color_charge_secondary_tier6_default")
|
||||
color_charge_secondary_tier5=$(get_tmux_option "@batt_color_charge_secondary_tier5" "$color_charge_secondary_tier5_default")
|
||||
color_charge_secondary_tier4=$(get_tmux_option "@batt_color_charge_secondary_tier4" "$color_charge_secondary_tier4_default")
|
||||
color_charge_secondary_tier3=$(get_tmux_option "@batt_color_charge_secondary_tier3" "$color_charge_secondary_tier3_default")
|
||||
color_charge_secondary_tier2=$(get_tmux_option "@batt_color_charge_secondary_tier2" "$color_charge_secondary_tier2_default")
|
||||
color_charge_secondary_tier1=$(get_tmux_option "@batt_color_charge_secondary_tier1" "$color_charge_secondary_tier1_default")
|
||||
}
|
||||
|
||||
print_color_charge() {
|
||||
local primary_plane="$1"
|
||||
local secondary_plane=""
|
||||
if [ "$primary_plane" == "bg" ]; then
|
||||
secondary_plane="fg"
|
||||
else
|
||||
secondary_plane="bg"
|
||||
fi
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
if [ $percentage -ge 95 -o "$percentage" == "" ]; then
|
||||
# if percentage is empty, assume it's a desktop
|
||||
printf "#[$primary_plane=$color_charge_primary_tier8${color_charge_secondary_tier8:+",$secondary_plane=$color_charge_secondary_tier8"}]"
|
||||
elif [ $percentage -ge 80 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier7${color_charge_secondary_tier7:+",$secondary_plane=$color_charge_secondary_tier7"}]"
|
||||
elif [ $percentage -ge 65 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier6${color_charge_secondary_tier6:+",$secondary_plane=$color_charge_secondary_tier6"}]"
|
||||
elif [ $percentage -ge 50 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier5${color_charge_secondary_tier5:+",$secondary_plane=$color_charge_secondary_tier5"}]"
|
||||
elif [ $percentage -ge 35 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier4${color_charge_secondary_tier4:+",$secondary_plane=$color_charge_secondary_tier4"}]"
|
||||
elif [ $percentage -ge 20 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier3${color_charge_secondary_tier3:+",$secondary_plane=$color_charge_secondary_tier3"}]"
|
||||
elif [ $percentage -gt 5 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier2${color_charge_secondary_tier2:+",$secondary_plane=$color_charge_secondary_tier2"}]"
|
||||
else
|
||||
printf "#[$primary_plane=$color_charge_primary_tier1${color_charge_secondary_tier1:+",$secondary_plane=$color_charge_secondary_tier1"}]"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local plane="$1"
|
||||
get_color_charge_settings
|
||||
print_color_charge "$plane"
|
||||
}
|
||||
|
||||
main $@
|
74
tmux/.tmux/plugins/tmux-battery/scripts/battery_color_status.sh
Executable file
74
tmux/.tmux/plugins/tmux-battery/scripts/battery_color_status.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
color_status_primary_charged=''
|
||||
color_status_primary_charging=''
|
||||
color_status_primary_discharging=''
|
||||
color_status_primary_attached=''
|
||||
color_status_primary_unknown=''
|
||||
color_status_secondary_charged=''
|
||||
color_status_secondary_charging=''
|
||||
color_status_secondary_discharging=''
|
||||
color_status_secondary_attached=''
|
||||
color_status_secondary_unknown=''
|
||||
|
||||
# script default variables
|
||||
color_status_primary_charged_default='colour33'
|
||||
color_status_primary_charging_default='colour33'
|
||||
color_status_primary_discharging_default='colour14'
|
||||
color_status_primary_attached_default='colour201'
|
||||
color_status_primary_unknown_default='colour7'
|
||||
color_status_secondary_charged_default='colour0'
|
||||
color_status_secondary_charging_default='colour0'
|
||||
color_status_secondary_discharging_default='colour0'
|
||||
color_status_secondary_attached_default='colour0'
|
||||
color_status_secondary_unknown_default='colour0'
|
||||
|
||||
# colors are set as script global variables
|
||||
get_color_status_settings() {
|
||||
color_status_primary_charged=$(get_tmux_option "@batt_color_status_primary_charged" "$color_status_primary_charged_default")
|
||||
color_status_primary_charging=$(get_tmux_option "@batt_color_status_primary_charging" "$color_status_primary_charging_default")
|
||||
color_status_primary_discharging=$(get_tmux_option "@batt_color_status_primary_discharging" "$color_status_primary_discharging_default")
|
||||
color_status_primary_attached=$(get_tmux_option "@batt_color_status_primary_attached" "$color_status_primary_attached_default")
|
||||
color_status_primary_unknown=$(get_tmux_option "@batt_color_status_primary_unknown" "$color_status_primary_unknown_default")
|
||||
color_status_secondary_charged=$(get_tmux_option "@batt_color_status_secondary_charged" "$color_status_secondary_charged_default")
|
||||
color_status_secondary_charging=$(get_tmux_option "@batt_color_status_secondary_charging" "$color_status_secondary_charging_default")
|
||||
color_status_secondary_discharging=$(get_tmux_option "@batt_color_status_secondary_discharging" "$color_status_secondary_discharging_default")
|
||||
color_status_secondary_attached=$(get_tmux_option "@batt_color_status_secondary_attached" "$color_status_secondary_attached_default")
|
||||
color_status_secondary_unknown=$(get_tmux_option "@batt_color_status_secondary_unknown" "$color_status_secondary_unknown_default")
|
||||
}
|
||||
|
||||
print_color_status() {
|
||||
local plane_primary="$1"
|
||||
local plane_secondary=""
|
||||
if [ "$plane_primary" == "bg" ]; then
|
||||
plane_secondary="fg"
|
||||
else
|
||||
plane_secondary="bg"
|
||||
fi
|
||||
local status="$2"
|
||||
if [[ $status =~ (charged) || $status =~ (full) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_charged${color_status_secondary_charged:+",$plane_secondary=$color_status_secondary_charged"}]"
|
||||
elif [[ $status =~ (^charging) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_charging${color_status_secondary_charging:+",$plane_secondary=$color_status_secondary_charging"}]"
|
||||
elif [[ $status =~ (^discharging) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_discharging${color_status_secondary_discharging:+",$plane_secondary=$color_status_secondary_discharging"}]"
|
||||
elif [[ $status =~ (attached) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_attached${color_status_secondary_attached:+",$plane_secondary=$color_status_secondary_attached"}]"
|
||||
else
|
||||
printf "#[$plane_primary=$color_status_primary_unknown${color_status_secondary_unknown:+",$plane_secondary=$color_status_secondary_unknown"}]"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local plane="$1"
|
||||
local status=${2:-$(battery_status)}
|
||||
get_color_status_settings
|
||||
print_color_status "$plane" "$status"
|
||||
}
|
||||
|
||||
main $@
|
45
tmux/.tmux/plugins/tmux-battery/scripts/battery_graph.sh
Executable file
45
tmux/.tmux/plugins/tmux-battery/scripts/battery_graph.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_graph() {
|
||||
local percentage=$1
|
||||
if [ $percentage -gt 5 ]; then
|
||||
printf "▁"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 25 ]; then
|
||||
printf "▂"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 50 ]; then
|
||||
printf "▄"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 75 ]; then
|
||||
printf "▆"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 95 ]; then
|
||||
printf "█"
|
||||
else
|
||||
printf " "
|
||||
echo "▇"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local percentage=$($CURRENT_DIR/battery_percentage.sh)
|
||||
if [ "$(uname)" == "OpenBSD" ]; then
|
||||
print_graph ${percentage}
|
||||
else
|
||||
print_graph ${percentage%?}
|
||||
fi
|
||||
}
|
||||
main
|
21
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon.sh
Executable file
21
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_icon() {
|
||||
local status=$1
|
||||
if [ "$status" == "discharging" ]; then
|
||||
$CURRENT_DIR/battery_icon_charge.sh
|
||||
else
|
||||
$CURRENT_DIR/battery_icon_status.sh "$status"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local status=$(battery_status)
|
||||
print_icon "$status"
|
||||
}
|
||||
|
||||
main
|
66
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon_charge.sh
Executable file
66
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon_charge.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
icon_charge_tier8=''
|
||||
icon_charge_tier7=''
|
||||
icon_charge_tier6=''
|
||||
icon_charge_tier5=''
|
||||
icon_charge_tier4=''
|
||||
icon_charge_tier3=''
|
||||
icon_charge_tier2=''
|
||||
icon_charge_tier1=''
|
||||
|
||||
# script default variables
|
||||
icon_charge_tier8_default='█'
|
||||
icon_charge_tier7_default='▇'
|
||||
icon_charge_tier6_default='▆'
|
||||
icon_charge_tier5_default='▅'
|
||||
icon_charge_tier4_default='▄'
|
||||
icon_charge_tier3_default='▃'
|
||||
icon_charge_tier2_default='▂'
|
||||
icon_charge_tier1_default='▁'
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_charge_settings() {
|
||||
icon_charge_tier8=$(get_tmux_option "@batt_icon_charge_tier8" "$icon_charge_tier8_default")
|
||||
icon_charge_tier7=$(get_tmux_option "@batt_icon_charge_tier7" "$icon_charge_tier7_default")
|
||||
icon_charge_tier6=$(get_tmux_option "@batt_icon_charge_tier6" "$icon_charge_tier6_default")
|
||||
icon_charge_tier5=$(get_tmux_option "@batt_icon_charge_tier5" "$icon_charge_tier5_default")
|
||||
icon_charge_tier4=$(get_tmux_option "@batt_icon_charge_tier4" "$icon_charge_tier4_default")
|
||||
icon_charge_tier3=$(get_tmux_option "@batt_icon_charge_tier3" "$icon_charge_tier3_default")
|
||||
icon_charge_tier2=$(get_tmux_option "@batt_icon_charge_tier2" "$icon_charge_tier2_default")
|
||||
icon_charge_tier1=$(get_tmux_option "@batt_icon_charge_tier1" "$icon_charge_tier1_default")
|
||||
}
|
||||
|
||||
print_icon_charge() {
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
if [ $percentage -ge 95 -o "$percentage" == "" ]; then
|
||||
# if percentage is empty, assume it's a desktop
|
||||
printf "$icon_charge_tier8"
|
||||
elif [ $percentage -ge 80 ]; then
|
||||
printf "$icon_charge_tier7"
|
||||
elif [ $percentage -ge 65 ]; then
|
||||
printf "$icon_charge_tier6"
|
||||
elif [ $percentage -ge 50 ]; then
|
||||
printf "$icon_charge_tier5"
|
||||
elif [ $percentage -ge 35 ]; then
|
||||
printf "$icon_charge_tier4"
|
||||
elif [ $percentage -ge 20 ]; then
|
||||
printf "$icon_charge_tier3"
|
||||
elif [ $percentage -gt 5 ]; then
|
||||
printf "$icon_charge_tier2"
|
||||
else
|
||||
printf "$icon_charge_tier1"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_charge_settings
|
||||
print_icon_charge
|
||||
}
|
||||
|
||||
main
|
61
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon_status.sh
Executable file
61
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon_status.sh
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
icon_status_charged=''
|
||||
icon_status_charging=''
|
||||
icon_status_discharging=''
|
||||
icon_status_attached=''
|
||||
icon_status_unknown=''
|
||||
|
||||
# script default variables
|
||||
icon_status_charged_default='🔌'
|
||||
icon_status_charged_default_osx='🔌'
|
||||
icon_status_charging_default='🔌'
|
||||
icon_status_discharging_default='🔋'
|
||||
icon_status_attached_default='⚠️'
|
||||
icon_status_unknown_default='?'
|
||||
|
||||
# determine which charged_default variable to use
|
||||
get_icon_status_charged_default() {
|
||||
if is_osx; then
|
||||
printf "$icon_status_charged_default_osx"
|
||||
else
|
||||
printf "$icon_status_charged_default"
|
||||
fi
|
||||
}
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_status_settings() {
|
||||
icon_status_charged=$(get_tmux_option "@batt_icon_status_charged" "$(get_icon_status_charged_default)")
|
||||
icon_status_charging=$(get_tmux_option "@batt_icon_status_charging" "$icon_status_charging_default")
|
||||
icon_status_discharging=$(get_tmux_option "@batt_icon_status_discharging" "$icon_status_discharging_default")
|
||||
icon_status_attached=$(get_tmux_option "@batt_icon_status_attached" "$icon_status_attached_default")
|
||||
icon_status_unknown=$(get_tmux_option "@batt_icon_status_unknown" "$icon_status_unknown_default")
|
||||
}
|
||||
|
||||
print_icon_status() {
|
||||
local status=$1
|
||||
if [[ $status =~ (charged) || $status =~ (full) ]]; then
|
||||
printf "$icon_status_charged"
|
||||
elif [[ $status =~ (^charging) ]]; then
|
||||
printf "$icon_status_charging"
|
||||
elif [[ $status =~ (^discharging) ]]; then
|
||||
printf "$icon_status_discharging"
|
||||
elif [[ $status =~ (attached) ]]; then
|
||||
printf "$icon_status_attached"
|
||||
else
|
||||
printf "$icon_status_unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_status_settings
|
||||
local status=${1:-$(battery_status)}
|
||||
print_icon_status "$status"
|
||||
}
|
||||
|
||||
main
|
45
tmux/.tmux/plugins/tmux-battery/scripts/battery_percentage.sh
Executable file
45
tmux/.tmux/plugins/tmux-battery/scripts/battery_percentage.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_battery_percentage() {
|
||||
# percentage displayed in the 2nd field of the 2nd row
|
||||
if is_wsl; then
|
||||
local battery
|
||||
battery=$(find /sys/class/power_supply/*/capacity | tail -n1)
|
||||
cat "$battery"
|
||||
elif command_exists "pmset"; then
|
||||
pmset -g batt | grep -o "[0-9]\{1,3\}%"
|
||||
elif command_exists "acpi"; then
|
||||
acpi -b | grep -m 1 -Eo "[0-9]+%"
|
||||
elif command_exists "upower"; then
|
||||
# use DisplayDevice if available otherwise battery
|
||||
local battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
|
||||
if [ -z "$battery" ]; then
|
||||
return
|
||||
fi
|
||||
local percentage=$(upower -i $battery | awk '/percentage:/ {print $2}')
|
||||
if [ "$percentage" ]; then
|
||||
echo ${percentage%.*%}
|
||||
return
|
||||
fi
|
||||
local energy
|
||||
local energy_full
|
||||
energy=$(upower -i $battery | awk -v nrg="$energy" '/energy:/ {print nrg+$2}')
|
||||
energy_full=$(upower -i $battery | awk -v nrgfull="$energy_full" '/energy-full:/ {print nrgfull+$2}')
|
||||
if [ -n "$energy" ] && [ -n "$energy_full" ]; then
|
||||
echo $energy $energy_full | awk '{printf("%d%%", ($1/$2)*100)}'
|
||||
fi
|
||||
elif command_exists "termux-battery-status"; then
|
||||
termux-battery-status | jq -r '.percentage' | awk '{printf("%d%%", $1)}'
|
||||
elif command_exists "apm"; then
|
||||
apm -l
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_battery_percentage
|
||||
}
|
||||
main
|
130
tmux/.tmux/plugins/tmux-battery/scripts/battery_remain.sh
Executable file
130
tmux/.tmux/plugins/tmux-battery/scripts/battery_remain.sh
Executable file
@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
short=false
|
||||
|
||||
get_remain_settings() {
|
||||
short=$(get_tmux_option "@batt_remain_short" false)
|
||||
}
|
||||
|
||||
battery_discharging() {
|
||||
local status="$(battery_status)"
|
||||
[[ $status =~ (discharging) ]]
|
||||
}
|
||||
|
||||
battery_charged() {
|
||||
local status="$(battery_status)"
|
||||
[[ $status =~ (charged) || $status =~ (full) ]]
|
||||
}
|
||||
|
||||
|
||||
convertmins() {
|
||||
((h=${1}/60))
|
||||
((m=${1}%60))
|
||||
printf "%02d:%02d\n" $h $m $s
|
||||
}
|
||||
|
||||
apm_battery_remaining_time() {
|
||||
local remaining_time="$(convertmins $(apm -m))"
|
||||
if battery_discharging; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s left", $1}'
|
||||
fi
|
||||
elif battery_charged; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "charged", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "fully charged", $1}'
|
||||
fi
|
||||
else
|
||||
echo "charging"
|
||||
fi
|
||||
}
|
||||
|
||||
pmset_battery_remaining_time() {
|
||||
local status="$(pmset -g batt)"
|
||||
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
|
||||
if $short; then
|
||||
echo '~?:??'
|
||||
else
|
||||
echo '- Calculating estimate...'
|
||||
fi
|
||||
else
|
||||
local remaining_time="$(echo $status | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}')"
|
||||
if battery_discharging; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s left", $1}'
|
||||
fi
|
||||
elif battery_charged; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "charged", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "fully charged", $1}'
|
||||
fi
|
||||
else
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s till full", $1}'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
upower_battery_remaining_time() {
|
||||
battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
|
||||
if battery_discharging; then
|
||||
local remaining_time
|
||||
remaining_time=$(upower -i "$battery" | grep -E '(remain|time to empty)')
|
||||
if $short; then
|
||||
echo "$remaining_time" | awk '{printf "%s %s", $(NF-1), $(NF)}'
|
||||
else
|
||||
echo "$remaining_time" | awk '{printf "%s %s left", $(NF-1), $(NF)}'
|
||||
fi
|
||||
elif battery_charged; then
|
||||
if $short; then
|
||||
echo ""
|
||||
else
|
||||
echo "charged"
|
||||
fi
|
||||
else
|
||||
local remaining_time
|
||||
remaining_time=$(upower -i "$battery" | grep -E 'time to full')
|
||||
if $short; then
|
||||
echo "$remaining_time" | awk '{printf "%s %s", $(NF-1), $(NF)}'
|
||||
else
|
||||
echo "$remaining_time" | awk '{printf "%s %s to full", $(NF-1), $(NF)}'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
acpi_battery_remaining_time() {
|
||||
acpi -b | grep -m 1 -Eo "[0-9]+:[0-9]+:[0-9]+"
|
||||
}
|
||||
|
||||
print_battery_remain() {
|
||||
if is_wsl; then
|
||||
echo "?" # currently unsupported on WSL
|
||||
elif command_exists "pmset"; then
|
||||
pmset_battery_remaining_time
|
||||
elif command_exists "acpi"; then
|
||||
acpi_battery_remaining_time
|
||||
elif command_exists "upower"; then
|
||||
upower_battery_remaining_time
|
||||
elif command_exists "apm"; then
|
||||
apm_battery_remaining_time
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_remain_settings
|
||||
print_battery_remain
|
||||
}
|
||||
main
|
50
tmux/.tmux/plugins/tmux-battery/scripts/battery_status_bg.sh
Executable file
50
tmux/.tmux/plugins/tmux-battery/scripts/battery_status_bg.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
color_full_charge_default="#[bg=green]"
|
||||
color_high_charge_default="#[bg=yellow]"
|
||||
color_medium_charge_default="#[bg=colour208]" # orange
|
||||
color_low_charge_default="#[bg=red]"
|
||||
color_charging_default="#[bg=green]"
|
||||
|
||||
color_full_charge=""
|
||||
color_high_charge=""
|
||||
color_medium_charge=""
|
||||
color_low_charge=""
|
||||
color_charging=""
|
||||
|
||||
get_charge_color_settings() {
|
||||
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
|
||||
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
|
||||
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
|
||||
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
|
||||
color_charging=$(get_tmux_option "@batt_color_charging" "$color_charging_default")
|
||||
}
|
||||
|
||||
print_battery_status_bg() {
|
||||
# Call `battery_percentage.sh`.
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
status=$(battery_status | awk '{print $1;}')
|
||||
if [ $status == 'charging' ]; then
|
||||
printf $color_charging
|
||||
elif [ $percentage -eq 100 ]; then
|
||||
printf $color_full_charge
|
||||
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
|
||||
printf $color_high_charge
|
||||
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
|
||||
printf $color_medium_charge
|
||||
elif [ "$percentage" == "" ];then
|
||||
printf $color_full_charge_default # assume it's a desktop
|
||||
else
|
||||
printf $color_low_charge
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_charge_color_settings
|
||||
print_battery_status_bg
|
||||
}
|
||||
main
|
50
tmux/.tmux/plugins/tmux-battery/scripts/battery_status_fg.sh
Executable file
50
tmux/.tmux/plugins/tmux-battery/scripts/battery_status_fg.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
color_full_charge_default="#[fg=green]"
|
||||
color_high_charge_default="#[fg=yellow]"
|
||||
color_medium_charge_default="#[fg=colour208]" # orange
|
||||
color_low_charge_default="#[fg=red]"
|
||||
color_charging_default="#[fg=green]"
|
||||
|
||||
color_full_charge=""
|
||||
color_high_charge=""
|
||||
color_medium_charge=""
|
||||
color_low_charge=""
|
||||
color_charging=""
|
||||
|
||||
get_charge_color_settings() {
|
||||
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
|
||||
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
|
||||
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
|
||||
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
|
||||
color_charging=$(get_tmux_option "@batt_color_charging" "$color_charging_default")
|
||||
}
|
||||
|
||||
print_battery_status_fg() {
|
||||
# Call `battery_percentage.sh`.
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
status=$(battery_status | awk '{print $1;}')
|
||||
if [ $status == 'charging' ]; then
|
||||
printf $color_charging
|
||||
elif [ $percentage -eq 100 ]; then
|
||||
printf $color_full_charge
|
||||
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
|
||||
printf $color_high_charge
|
||||
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
|
||||
printf $color_medium_charge
|
||||
elif [ "$percentage" == "" ];then
|
||||
printf $color_full_charge_default # assume it's a desktop
|
||||
else
|
||||
printf $color_low_charge
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_charge_color_settings
|
||||
print_battery_status_fg
|
||||
}
|
||||
main
|
63
tmux/.tmux/plugins/tmux-battery/scripts/helpers.sh
Normal file
63
tmux/.tmux/plugins/tmux-battery/scripts/helpers.sh
Normal file
@ -0,0 +1,63 @@
|
||||
get_tmux_option() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value="$(tmux show-option -gqv "$option")"
|
||||
if [ -z "$option_value" ]; then
|
||||
echo "$default_value"
|
||||
else
|
||||
echo "$option_value"
|
||||
fi
|
||||
}
|
||||
|
||||
is_osx() {
|
||||
[ $(uname) == "Darwin" ]
|
||||
}
|
||||
|
||||
is_chrome() {
|
||||
chrome="/sys/class/chromeos/cros_ec"
|
||||
if [ -d "$chrome" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_wsl() {
|
||||
version=$(</proc/version)
|
||||
if [[ "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
type "$command" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
battery_status() {
|
||||
if is_wsl; then
|
||||
local battery
|
||||
battery=$(find /sys/class/power_supply/*/status | tail -n1)
|
||||
awk '{print tolower($0);}' "$battery"
|
||||
elif command_exists "pmset"; then
|
||||
pmset -g batt | awk -F '; *' 'NR==2 { print $2 }'
|
||||
elif command_exists "acpi"; then
|
||||
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'
|
||||
elif command_exists "upower"; then
|
||||
local battery
|
||||
battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
|
||||
upower -i $battery | awk '/state/ {print $2}'
|
||||
elif command_exists "termux-battery-status"; then
|
||||
termux-battery-status | jq -r '.status' | awk '{printf("%s%", tolower($1))}'
|
||||
elif command_exists "apm"; then
|
||||
local battery
|
||||
battery=$(apm -a)
|
||||
if [ $battery -eq 0 ]; then
|
||||
echo "discharging"
|
||||
elif [ $battery -eq 1 ]; then
|
||||
echo "charging"
|
||||
fi
|
||||
fi
|
||||
}
|
Reference in New Issue
Block a user