Created
August 6, 2009 00:54
-
-
Save badboy/163070 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
i3-dzen.rb | dzen2 -dock -ta r -fn "-*-terminus-medium-r-normal--14-120-75-75-C-70-iso8859-1" |
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
#!/usr/bin/env ruby19 | |
# encoding: utf-8 | |
require 'time' | |
DZEN_CONFIG = { | |
:delimiter => "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)", | |
:ending => "^p(6)\n", | |
:interval => 3 | |
} | |
$rfkill = '/sys/devices/platform/acer-wmi/rfkill/rfkill0/state' | |
if !File.exist?($rfkill) | |
$rfkill = '/sys/devices/platform/acer-wmi/rfkill/rfkill1/state' | |
end | |
class DZEN | |
def initialize(options) | |
@interval = options.delete(:interval) || 3 | |
@delimiter = options.delete(:delimiter) || '|' | |
@ending = options.delete(:ending) || "\n" | |
@modules = [] | |
end | |
def <<(other) | |
@modules << other | |
self | |
end | |
def run | |
trap(:INT) { puts; exit 1; } | |
loop do | |
puts @modules.map{|e| e.respond_to?(:call) ? e.call : e.to_s}.join(@delimiter) + @ending | |
sleep @interval | |
end | |
rescue Errno::EPIPE | |
exit 0 | |
end | |
def self.color(color, text) | |
"^fg(#{color})#{text}^fg()" | |
end | |
end | |
puts "--- loading ---#{DZEN_CONFIG[:ending]}" | |
gajim = -> do | |
unread = `export LC_ALL=C; gajim-remote get_unread_msgs_number 2>&1`.chomp | |
if unread.match(/gajim is not running/i) | |
"gajim: -" | |
elsif unread.to_i == 0 | |
"gajim: 0" | |
elsif unread.to_i < 11 | |
"gajim: #{DZEN.color('#ff8700', unread)}" | |
else | |
"gajim: #{DZEN.color(:red, unread)}" | |
end | |
end | |
pidgin = "pidgin unread: -" | |
#-> do | |
#unread = `pidgin-unread.py 2>/dev/null`.to_i | |
#if unread == 0 | |
# "pidgin unread: #{unread}" | |
#elsif unread < 10 | |
# "pidgin unread: ^fg(#ff8700)#{unread}^fg()" | |
#else | |
# "pidgin unread: ^fg(red)#{unread}^fg()" | |
#end | |
#end | |
hdd_temp = -> { "HDD: #{`nc localhost 7634`.split(/\|/)[-2]}°C" } | |
cpu_temp = -> { "CPU: #{`sensors`.scan(/temp\d:\s+\+(\d+\.\d+)/).flatten.map{|t|"#{t}°C"}.join('/')}" } | |
cpu_freq = -> { "@#{`cpufreq-info`.scan(/momentane Taktfrequenz ist (.+)./).flatten.first}" } | |
cpu = -> { "#{cpu_temp.call} #{cpu_freq.call}" } | |
battery = -> do | |
bat = `acpi -i` | |
ac = `acpi -a`.match(/: on-line/) | |
if bat.empty? | |
if ac | |
'ac adapter' | |
else | |
'battery: -' | |
end | |
else | |
if md = bat.match(/(\d+)%/) | |
per = md[1].to_i | |
if bat.match(/Charging/) | |
charge = ' (charging)' | |
end | |
if bat.match(/Full/) | |
charge = ' (full)' | |
end | |
if t = bat.match(/(\d\d:\d\d):/) | |
left = " (#{t[1]})" | |
end | |
if per < 20 | |
DZEN.color('#ff8700', "battery: #{per}%#{charge}#{left}") | |
end | |
if per < 11 | |
DZEN.color(:red, "battery: #{per}%#{charge}#{left}") | |
else | |
"battery: #{per}%#{charge}" | |
end | |
else | |
DZEN.color(:red, 'battery: -') | |
end | |
end | |
end | |
wlan_switch = -> { "wlan: #{File.read($rfkill).to_i == 0 ? 'off' : 'on'}" rescue "wlan: -" } | |
time = -> { Time.now.strftime("%d.%m.%Y %H:%M") } | |
loadavg = -> { IO.read('/proc/loadavg').split(/ /)[0,3].join(' ') } | |
dzen = DZEN.new(DZEN_CONFIG) | |
dzen << gajim << battery << wlan_switch << hdd_temp << cpu << loadavg << time | |
dzen.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment