Skip to content

Instantly share code, notes, and snippets.

@badboy
Created September 30, 2009 17:36
Show Gist options
  • Save badboy/198275 to your computer and use it in GitHub Desktop.
Save badboy/198275 to your computer and use it in GitHub Desktop.
#!/bin/bash
./i3-dzen.rb | dzen2 -ta r -fn "-*-terminus-medium-r-normal--14-120-75-75-C-70-iso8859-1" -y 1031 -expand left -bg black -dock
#!/usr/bin/env ruby
# encoding: utf-8
#
# 20:24 <Rasi> wenn du dir die muehe machen willst.. ich haett das gleiche gern ohne pidgin und gajim aber mit mpd
# 20:27 <Rasi> und wenns irgendwie moeglich ist click events
# 20:27 <Rasi> links click next track, rightclick pause
#
require 'time'
DZEN_CONFIG = {
:delimiter => "^fg(#333333)^p(5;-2)^ro(2)^p()^fg()^p(5)",
:ending => "^p(6)\n",
:interval => 1
}
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
def self.click(button, cmd, text)
"^ca(#{button}, #{cmd})#{text}^ca()"
end
def self.img(src)
"^i(#{src})"
end
end
puts "--- loading ---#{DZEN_CONFIG[:ending]}"
ICON_PATH = "./img"
ICONS = {
:music => "mpd.xbm",
:play => "play.xbm",
:pause => "pause.xbm",
:stop => "stop.xbm",
:prev => "prev.xbm",
:next => "next.xbm"
}
mpd = -> do
current = `mpc current`.chomp
current = "[stopped]" if current.empty?
status = `mpc status`
play_stop = '-'
if status =~ /\[playing\]/
play_stop = "#{DZEN.click(1, 'mpc stop &>/dev/null', DZEN.img(File.join(ICON_PATH, ICONS[:stop])))}"
else
play_stop = "#{DZEN.click(1, 'mpc play &>/dev/null', DZEN.img(File.join(ICON_PATH, ICONS[:play])))}"
end
res = (<<EOF).gsub(/\n/, ' ')
#{DZEN.click(1, 'mpc prev &>/dev/null', DZEN.img(File.join(ICON_PATH, ICONS[:prev])))}
#{DZEN.click(1, 'mpc toggle &>/dev/null', DZEN.img(File.join(ICON_PATH, ICONS[:pause])))}
#{play_stop}
#{DZEN.click(1, 'mpc next &>/dev/null', DZEN.img(File.join(ICON_PATH, ICONS[:next])))}
#{DZEN.img(File.join(ICON_PATH, ICONS[:music]))}
#{current}
EOF
end
hdd_temp = -> { "HDD: #{`nc localhost 7634`.split(/\|/)[-2]}°C" }
cpu_temp = -> { "CPU: #{`sensors`.scan(/temp:\s+\+(\d+\.\d+..)/i).flatten.first}" }
time = -> { Time.now.strftime("%d.%m.%Y %H:%M") }
loadavg = -> { IO.read('/proc/loadavg').split(/ /)[0,3].join(' ') }
dzen = DZEN.new(DZEN_CONFIG)
dzen << mpd << hdd_temp << cpu_temp << loadavg << time
dzen.run
#define mpd_width 16
#define mpd_height 16
static unsigned char mpd_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x1f, 0x40, 0x10,
0x40, 0x10, 0x40, 0x10, 0x40, 0x10, 0x40, 0x10, 0x70, 0x1c, 0x78, 0x1e,
0x30, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
#define next_width 8
#define next_height 8
static unsigned char next_bits[] = {
0x00, 0x42, 0x4E, 0x7E, 0x7E, 0x4E, 0x42, 0x00 };
#define pause_width 8
#define pause_height 8
static unsigned char pause_bits[] = {
0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00 };
#!/usr/bin/env python
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
def detect_unread_conversations(purple):
convs = purple.PurpleGetConversations()
count = 0
for conv in convs:
count += purple.PurpleConversationGetData(conv, "unseen-count")
print(count)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
detect_unread_conversations(purple)
#define play_width 8
#define play_height 8
static unsigned char play_bits[] = {
0x00, 0x06, 0x1E, 0x7E, 0x7E, 0x1E, 0x06, 0x00 };
#define prev_width 8
#define prev_height 8
static unsigned char prev_bits[] = {
0x00, 0x42, 0x72, 0x7E, 0x7E, 0x72, 0x42, 0x00 };
#define stop_width 8
#define stop_height 8
static char stop_bits[] = {
0x00, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x00, };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment