Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
pattern
ohmybash
oh-my-bash
提交
7a3a7b01
O
oh-my-bash
项目概览
pattern
/
ohmybash
/
oh-my-bash
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oh-my-bash
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7a3a7b01
编写于
2月 17, 2020
作者:
K
Kreyren
提交者:
GitHub
2月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
plugins/battery: Attempt to fix
https://github.com/ohmybash/oh-my-bash/issues/68
(#104)
Fixes:
https://github.com/ohmybash/oh-my-bash/issues/68
上级
27b55d1e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
15 deletion
+18
-15
plugins/battery/battery.plugin.sh
plugins/battery/battery.plugin.sh
+18
-15
未找到文件。
plugins/battery/battery.plugin.sh
浏览文件 @
7a3a7b01
#!/usr/bin/env bash
# Bug: https://github.com/ohmybash/oh-my-bash/issues/68
if
!
command
-v
"command_exists"
>
/dev/null
;
then
command_exists
()
{
command
-v
"
$1
"
>
/dev/null
;
}
fi
ac_adapter_connected
(){
if
_
command_exists upower
;
if
command_exists upower
;
then
upower
-i
$(
upower
-e
|
grep
BAT
)
|
grep
'state'
|
grep
-q
'charging\|fully-charged'
return
$?
elif
_
command_exists acpi
;
elif
command_exists acpi
;
then
acpi
-a
|
grep
-q
"on-line"
return
$?
elif
_
command_exists pmset
;
elif
command_exists pmset
;
then
pmset
-g
batt |
grep
-q
'AC Power'
return
$?
elif
_
command_exists ioreg
;
elif
command_exists ioreg
;
then
ioreg
-n
AppleSmartBattery
-r
|
grep
-q
'"ExternalConnected" = Yes'
return
$?
elif
_
command_exists WMIC
;
elif
command_exists WMIC
;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List |
grep
-q
'BatteryStatus=2'
return
$?
...
...
@@ -25,23 +28,23 @@ ac_adapter_connected(){
}
ac_adapter_disconnected
(){
if
_
command_exists upower
;
if
command_exists upower
;
then
upower
-i
$(
upower
-e
|
grep
BAT
)
|
grep
'state'
|
grep
-q
'discharging'
return
$?
elif
_
command_exists acpi
;
elif
command_exists acpi
;
then
acpi
-a
|
grep
-q
"off-line"
return
$?
elif
_
command_exists pmset
;
elif
command_exists pmset
;
then
pmset
-g
batt |
grep
-q
'Battery Power'
return
$?
elif
_
command_exists ioreg
;
elif
command_exists ioreg
;
then
ioreg
-n
AppleSmartBattery
-r
|
grep
-q
'"ExternalConnected" = No'
return
$?
elif
_
command_exists WMIC
;
elif
command_exists WMIC
;
then
WMIC Path Win32_Battery Get BatteryStatus /Format:List |
grep
-q
'BatteryStatus=1'
return
$?
...
...
@@ -52,11 +55,11 @@ battery_percentage(){
about
'displays battery charge as a percentage of full (100%)'
group
'battery'
if
_
command_exists upower
;
if
command_exists upower
;
then
local
UPOWER_OUTPUT
=
$(
upower
--show-info
$(
upower
--enumerate
|
grep
BAT
)
|
grep
percentage |
tail
--bytes
5
)
echo
${
UPOWER_OUTPUT
:
:
-1
}
elif
_
command_exists acpi
;
elif
command_exists acpi
;
then
local
ACPI_OUTPUT
=
$(
acpi
-b
)
case
$ACPI_OUTPUT
in
...
...
@@ -83,7 +86,7 @@ battery_percentage(){
echo
'-1'
;;
esac
elif
_
command_exists pmset
;
elif
command_exists pmset
;
then
local
PMSET_OUTPUT
=
$(
pmset
-g
ps |
sed
-n
's/.*[[:blank:]]+*\(.*%\).*/\1/p'
)
case
$PMSET_OUTPUT
in
...
...
@@ -94,7 +97,7 @@ battery_percentage(){
echo
$PMSET_OUTPUT
|
head
-c
2
;;
esac
elif
_
command_exists ioreg
;
elif
command_exists ioreg
;
then
local
IOREG_OUTPUT
=
$(
ioreg
-n
AppleSmartBattery
-r
|
awk
'$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}'
)
case
$IOREG_OUTPUT
in
...
...
@@ -105,7 +108,7 @@ battery_percentage(){
echo
$IOREG_OUTPUT
|
head
-c
2
;;
esac
elif
_
command_exists WMIC
;
elif
command_exists WMIC
;
then
local
WINPC
=
$(
echo
porcent
=
$(
WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List
)
|
grep
-o
'[0-9]*'
)
case
$WINPC
in
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录