Create the concept of enabled plugins
This allows users to disable a plugin without completely removing it. Instead, they simply remove the `plugins/enabled/*.bash` file for the plugin they want to disable. This continues the concept of "everything on" while providing greater flexibility to future users. It might be a good idea to allow turning these off by default in the future and allowing not only the `plugins/enabled/*.bash` files but also an array of `<plugin_name>` values that would search for `plugins/available/<plugin_name>.plugin.bash` to enable them. That method would make it easier for people custom tune their plugins from within their `.bash_profile` script.
This commit is contained in:
129
plugins/available/battery.plugin.bash
Normal file
129
plugins/available/battery.plugin.bash
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/bin/bash
|
||||
|
||||
battery_percentage(){
|
||||
if command_exists acpi;
|
||||
then
|
||||
local ACPI_OUTPUT=$(acpi -b)
|
||||
case $ACPI_OUTPUT in
|
||||
*" Unknown"*)
|
||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 22 | tail -c 2)
|
||||
case $PERC_OUTPUT in
|
||||
*%)
|
||||
echo "0${PERC_OUTPUT}" | head -c 2
|
||||
;;
|
||||
*)
|
||||
echo ${PERC_OUTPUT}
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*" Discharging"*)
|
||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 26 | tail -c 2)
|
||||
case $PERC_OUTPUT in
|
||||
*%)
|
||||
echo "0${PERC_OUTPUT}" | head -c 2
|
||||
;;
|
||||
*)
|
||||
echo ${PERC_OUTPUT}
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*" Charging"*)
|
||||
local PERC_OUTPUT=$(echo $ACPI_OUTPUT | head -c 23 | tail -c 2)
|
||||
case $PERC_OUTPUT in
|
||||
*%)
|
||||
echo "0${PERC_OUTPUT}" | head -c 2
|
||||
;;
|
||||
*)
|
||||
echo ${PERC_OUTPUT}
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*" Full"*)
|
||||
echo '99'
|
||||
;;
|
||||
*)
|
||||
echo '-1'
|
||||
;;
|
||||
esac
|
||||
elif command_exists ioreg;
|
||||
then
|
||||
# http://hints.macworld.com/article.php?story=20100130123935998
|
||||
#local IOREG_OUTPUT_10_6=$(ioreg -l | grep -i capacity | tr '\n' ' | ' | awk '{printf("%.2f%%", $10/$5 * 100)}')
|
||||
#local IOREG_OUTPUT_10_5=$(ioreg -l | grep -i capacity | grep -v Legacy| tr '\n' ' | ' | awk '{printf("%.2f%%", $14/$7 * 100)}')
|
||||
local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}')
|
||||
case $IOREG_OUTPUT in
|
||||
100*)
|
||||
echo '99'
|
||||
;;
|
||||
*)
|
||||
echo $IOREG_OUTPUT | head -c 2
|
||||
;;
|
||||
esac
|
||||
else
|
||||
echo "no"
|
||||
fi
|
||||
}
|
||||
|
||||
battery_charge(){
|
||||
# Full char
|
||||
local F_C='▸'
|
||||
# Depleted char
|
||||
local D_C='▹'
|
||||
local DEPLETED_COLOR='\[${normal}\]'
|
||||
local FULL_COLOR='\[${green}\]'
|
||||
local HALF_COLOR='\[${yellow}\]'
|
||||
local DANGER_COLOR='\[${red}\]'
|
||||
local BATTERY_OUTPUT='${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${D_C}'
|
||||
local BATTERY_PERC=$(battery_percentage)
|
||||
|
||||
case $BATTERY_PERC in
|
||||
no)
|
||||
echo ""
|
||||
;;
|
||||
9*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${F_C}${normal}"
|
||||
;;
|
||||
8*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${normal}"
|
||||
;;
|
||||
7*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
||||
;;
|
||||
6*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${normal}"
|
||||
;;
|
||||
5*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
4*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
3*)
|
||||
echo "${FULL_COLOR}${F_C}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
2*)
|
||||
echo "${FULL_COLOR}${F_C}${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
1*)
|
||||
echo "${FULL_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
05)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
04)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
03)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
02)
|
||||
echo "${DANGER_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
0*)
|
||||
echo "${HALF_COLOR}${F_C}${DEPLETED_COLOR}${D_C}${D_C}${D_C}${D_C}${normal}"
|
||||
;;
|
||||
*)
|
||||
echo "${DANGER_COLOR}UNPLG\[${normal}\]"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
Reference in New Issue
Block a user