FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bash-it/plugins/available/battery.plugin.bash at master · gitanicsoftware/bash-it · GitHub
gitanicsoftware
bash-it
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
bash-it
/
plugins
/
available
/
battery.plugin.bash
Copy path
More file actions
More file actions
Latest commit
History
History
History
136 lines (131 loc) · 3.78 KB
Breadcrumbs
bash-it
/
plugins
/
available
/
battery.plugin.bash
Copy path
File metadata and controls
136 lines (131 loc) · 3.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cite about-plugin
about-plugin
'
display info about your battery charge level
'
battery_percentage
(){
about
'
displays battery charge as a percentage of full (100%)
'
group
'
battery
'
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
(){
about
'
graphical display of your battery charge
'
group
'
battery
'
#
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
}
Back
|
FazBrowse Home
|
New Git URL