sr (owner)

Revisions

  • ac8f2a sr Sat Jul 04 12:27:14 -0700 2009
gist: 140672 Download_button fork
public
Description:
my dwm status bar (in both Io and Ruby)
Public Clone URL: git://gist.github.com/140672.git
Embed All Files: show embed
dwm-bar.io #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env io
date := Date now asString("%Y-%m-%d %H:%M:%S")
 
wifi := File clone openForReading("/proc/net/wireless") readLines \
  at(2) split at(5) removeAt(2) asString
 
mpd := method(
  File clone openForReading("/home/simon/.mpd/state") foreachLine(i, line,
    parts := line split(":")
    if(parts at(0) == "state", state := parts at(1))
    if(parts at(0) == "current", current := parts at(1) lstrip)
    if(slotNames contains("current") and parts at(0) == current,
      return parts at(1))
  )
)
 
"[M: #{mpd}] [W: #{wifi}] ||| #{date}]" interpolate print
dwm-bar.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
require "librmpd"
 
def date
  Time.now.strftime("%Y-%m-%d %H:%M")
end
 
def mpd
  song = MPD.new.tap { |mpd| mpd.connect }.current_song
  return "NA" unless song
 
  if song.artist && song.album && song.title
    "#{song.artist} - #{song.album} - #{song.title}"
  else
    song.file[50..song.file.size]
  end
end
 
def battery
  state = File.readlines("/proc/acpi/battery/BAT0/state").map { |line|
    line.gsub(/.*:\s*/, "").chomp }
  info = File.readlines("/proc/acpi/battery/BAT0/info").map { |line|
    line.gsub(/.*:\s*/, "").chomp }
  percentage = ((state[4].chomp("mAh").to_f /
    info[2].chomp("mAh").to_f ) * 100).to_i
  status = state[2]
 
  indicator = case status
    when "charged" then "="
    when "charging" then "^"
    when "discharging" then "v"
    else ""
  end
 
  if status == "discharging" && percentage <= 10
    xmessage = "xmessage -butt xmessage -buttons quit:0 -default quit -file -"
    IO.popen(xmessage, "w") { |io| io << "ZOMFGWTF CRITICAL BATTERY" }
  end
 
  "#{indicator}#{percentage}%"
end
 
def wifi
  info = File.readlines("/proc/net/wireless")
  info[2][/wlan0: \d{4}\s*(\d+)\./] && $1
rescue
  0
end
 
puts "[M: #{mpd}] | [B: #{battery}] | [W: #{wifi}] ||| #{date}"