Created
July 7, 2011 05:14
-
-
Save julie86/1068921 to your computer and use it in GitHub Desktop.
Ruby script to generate a dzen statusbar for stumpwm. using ruby-dzen.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'dzen' | |
include DZEN::Helpers | |
# Config | |
COLOR = "#DA4939" | |
INTERFACE = "wlan0" | |
WEECHATLOG = "/home/crshd/.weechat/logs/perl.highmon.weechatlog" | |
@rxo = IO.read("/sys/class/net/#{INTERFACE}/statistics/rx_bytes").to_i | |
@txo = IO.read("/sys/class/net/#{INTERFACE}/statistics/tx_bytes").to_i | |
configure do |c| | |
c.interval = 1 | |
c.delimiter = _color("#404040", " ") | |
c.output = $stdout | |
end | |
before_run do # {{{ | |
"--- loading ---#{DZEN::Base::Config[:ending]}#{updatepacman}" | |
end # }}} | |
app :cpu do # {{{ | |
"^pa(600)" + _color(COLOR, "CPU ") + | |
%x[sensors].scan(/Core \d:\s+\+(\d+)\.\d/).flatten.map{|e|"#{e}°C"}.join(" ") | |
end # }}} | |
app :loadavg do # {{{ | |
_color(COLOR, "LOAD ") + | |
IO.read('/proc/loadavg').split(/ /)[0,3].join(' ') | |
end # }}} | |
app :speed do # {{{ | |
_color(COLOR, INTERFACE.upcase) + " #{speed}" | |
end | |
def speed | |
rx = IO.read("/sys/class/net/#{INTERFACE}/statistics/rx_bytes").to_i | |
tx = IO.read("/sys/class/net/#{INTERFACE}/statistics/tx_bytes").to_i | |
string = "%3ik %2ik" % [((rx - @rxo) / 1024), ((tx - @txo) / 1024)] | |
@rxo, @txo = rx, tx | |
return string | |
end | |
# }}} | |
app :time do # {{{ | |
_color(COLOR, "TIME ") + Time.now.strftime("%d.%m.%Y %H:%M") | |
end # }}} | |
app :irc do # {{{ | |
_color(COLOR, "IRC ") + irc | |
end | |
def irc | |
msg = IO.readlines(WEECHATLOG)[-1].split(/ /)[1].split("\t") | |
return [msg[0], msg[1].split("#")[1], msg[2]].join(" ") | |
end # }}} | |
app :pacman do # {{{ | |
pacman | |
end | |
def updatepacman | |
Thread.new { | |
loop do | |
$updates = %x[clyde -Qu].split("\n") | |
sleep 300 | |
end | |
} | |
end | |
def pacman | |
Thread.new { | |
sleep 1 | |
@string = _color(COLOR, "PKG") | |
["core/", "extra/", "community/"].each { |r| | |
@string += " " + $updates.find_all { |a| | |
a.include? r | |
}.size.to_s | |
} | |
} | |
return @string | |
end # }}} | |
app :groups do # {{{ | |
getgroups | |
end | |
def getgroups | |
groups, active, string, id = Array.new, Array.new, "", 0 | |
%x[wmctrl -d].split("\n").each { |g| | |
groups.concat([g.split.last]) | |
active.concat([g.split[1]]) | |
} | |
hash = Hash[groups.zip(active)] | |
hash.each { |g,a| | |
string += "^ca(1,wmctrl -s #{id})" | |
if a == "*" | |
string += "^bg(#{COLOR}) #{g.upcase} ^bg()" | |
else | |
string += " #{g.upcase} " | |
end | |
string += "^ca()" | |
id += 1 | |
} | |
return string | |
end # }}} | |
app :mail do # {{{ | |
_color(COLOR, "MAIL") + mail | |
end | |
def mail | |
count = "" | |
%w{Gmail Mail}.each { |m| | |
count += " " + (Dir.entries("/media/data/Mail/#{m}/INBOX/new").size - 2).to_s | |
} | |
return count | |
end # }}} | |
order :groups, :cpu, :loadavg, :speed, :time, :irc, :pacman, :mail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment