Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple batstat ascii art for tmux status bar
- Loading branch information
1 parent
013bdfa
commit e7846f5
Showing
1 changed file
with
34 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
#encoding: utf-8 | ||
|
||
import os | ||
|
||
BASE = '/proc/acpi/battery/BAT0' | ||
|
||
STATE = os.path.join(BASE, 'state') | ||
INFO = os.path.join(BASE, 'info') | ||
|
||
|
||
def build_hash(file): | ||
h = {} | ||
if not os.path.exists(file): | ||
return {} | ||
for line in open(file): | ||
key, value = line.split(':') | ||
h[key.replace(' ', '').strip()] = value.strip().strip('\n') | ||
return h | ||
|
||
|
||
state_hash = build_hash(STATE) | ||
info_hash = build_hash(INFO) | ||
#print state_hash, info_hash | ||
|
||
total_capacity = int(info_hash['designcapacity'].split()[0]) | ||
current_capacity = int(state_hash['remainingcapacity'].split()[0]) | ||
|
||
total = int(float(current_capacity) / float(total_capacity) * 10) | ||
bars = total * "|" | ||
print "-{0}{1}+".format(bars, (10 - total) * ' ') | ||
|
||
|
||
|