-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# micro-battery | ||
Display battery percentage for micro | ||
Displays battery percentage on micro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
VERSION = "0.0.1" | ||
|
||
local micro = import("micro") | ||
local shell = import("micro/shell") | ||
local config = import("micro/config") | ||
|
||
function init() | ||
config.MakeCommand("battery", percentage, config.NoComplete) | ||
config.TryBindKey("F7", "lua:battery.percentage", false) | ||
end | ||
|
||
-- Runs command and filter one line that has what is in contains | ||
function RunCommandAndGrep(input, contains) | ||
local ret, err = shell.RunCommand(input) | ||
if err ~= nil then | ||
micro.Log("Error while running " .. input) | ||
end | ||
|
||
local result = "" | ||
for s in ret:gmatch("[^\r\n]+") do | ||
if string.find(s, contains) then | ||
result = s | ||
end | ||
end | ||
return result | ||
end | ||
|
||
-- percentage print the battery percentage on the infobar as message. | ||
-- The function emulate the next cli command | ||
-- upower -i $(upower -e | grep BAT) | grep --color=never -E "percentage" | ||
function percentage(bp) | ||
-- get devices and select the battery one | ||
local device, err = RunCommandAndGrep("upower -e", "BAT") | ||
if err ~= nil then | ||
micro.Log("Error while running upower") | ||
end | ||
|
||
-- query the device BATtery and filter the line with the percentage | ||
local batteryPercentage, err = RunCommandAndGrep("upower -i " .. device, "percentage") | ||
if err ~= nil then | ||
micro.Log("Error while running upower: " .. err) | ||
end | ||
|
||
-- display Battery percentage: x% | ||
micro.InfoBar():Message("Battery" .. batteryPercentage) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# battery Plugin # | ||
|
||
The battery plugin provides the user with the ability to display | ||
the battery percentage. | ||
|
||
Currently it depends on upower. | ||
|
||
To initiate the function, you can either: | ||
|
||
Press "F7" | ||
|
||
Or run: | ||
|
||
``` | ||
> battery | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "battery", | ||
"description": "Show battery percentage", | ||
"website": "", | ||
"install": "", | ||
"version": "0.0.1", | ||
"require": [ | ||
"micro >= 2.0.0" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[{ | ||
"Name": "battery", | ||
"Description": "Shows battery percentage on infobar", | ||
"Tags": ["upower", "laptop"], | ||
"Website": "https://github.com/dubyte/battery-plugin", | ||
"Versions": [ | ||
{ | ||
"Version": "0.0.1", | ||
"Url": "https://github.com/micro-editor/battery-plugin/archive/v0.0.1.zip", | ||
"Require": { | ||
"micro": ">=2.0.0" | ||
} | ||
} | ||
] | ||
}] | ||
|