Skip to content

Android phone battery level

Matthias Grundmann edited this page Jul 13, 2019 · 3 revisions

This plugin shows the battery level of a connected Android phone.

Requires ruby and adb. Check with adb devices that your phone is connected properly.

#!/usr/bin/env ruby

output = `adb shell dumpsys battery | grep level`
if output.empty?
	print "--\n"
	exit 0
end
matches = output.match(/.*: (\d+)\s*/)
charge = matches[1]
full_notice = charge.to_i > 85 ? " 🔋" : ""
print "📱 #{charge}%#{full_notice}\n"