Skip to content

Instantly share code, notes, and snippets.

@sletix
Last active November 18, 2015 16:44
Show Gist options
  • Save sletix/dbc8f7e456f384a2beb5 to your computer and use it in GitHub Desktop.
Save sletix/dbc8f7e456f384a2beb5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class RightTSnitch
# change me
def render
"#{bloody} #{power}#{battery} (~#{@percents}%)"
end
def initialize
# some parse pmset output
data = `/usr/bin/pmset -g batt |grep ';'`.split(';').map(&:strip)
@percents, @state, @time = [data[0].split("\t")[-1].to_i, data[1], data[2]]
end
private
#
# [T]ext Drawing Methods
# ----------------------
def battery
"#{'█'*cells_count}#{'░'*(5-cells_count)}∎"
# => '███░░∎'
end
def bloody
'💉' if cells_count == 0
end
def power
case @state
when 'AC attached', 'charged' then '⚡ '
when 'charging' then '⚡⚍'
else ' '
end
end
private
#
# helpers
# -------
def cells_count
(@percents*0.05).round
end
end
puts RightTSnitch.new.render

Alt tmux Battery Text Status



install (download and run)
 $ wget https://gist.githubusercontent.com/sletix/dbc8f7e456f384a2beb5/raw -O ~/.battery_percent
 $ chmod +x ~/.battery_percent
 $ ~/.battery_percent
 █████∎ (~100%)
using battery-info in tmux
  • add simple line in tmux.conf: set-option -g status-right "#(~/.battery_percent)"
  • or use this lines which include time and colors:
set-option -g status-right " #(~/.battery_percent) ::  (utc#(ruby -e \"puts Time.now.utc.to_s[11..12]\")) #(date '+%H:%M')"
set -g status-fg colour10
set -g status-bg colour7
  • reload tmux config Ctrl+B(tmux prefix) + :source-file ~/path/to/.tmux.conf

Alt tmux-photo Alt tmux-screenshot

@sadfuzzy
Copy link

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment