Some handy dwm scripts.
Ruby gmail checker */home/marko/bin/gmail\_checker.rb*, which I run from cron every 5 minutes and redirect the output to */home/marko/tmp/mail*. The gmail checker script is adapted from a [wmii gmail checker plugin](http://dmy999.com/src/gmail-check.rb)
*crontab entry*
```bash
*/5 * * * * ruby "/home/marko/bin/gmail_checker.rb" > /home/marko/tmp/mail
```
*/home/marko/bin/gmail\_checker.rb*
```bash
CERTPATH = '/etc/ssl/certs'
def gmail_check(username, password)
req = Net::HTTP::Get.new '/mail/feed/atom'
req.basic_auth(username, password)
http = Net::HTTP.new('mail.google.com', 443)
http.use_ssl = true
#http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.ca_path = CERTPATH
res = http.request req
doc = REXML::Document.new res.body
entries = doc.root.get_elements('/feed/entry')
return nil if entries.length == 0
title = entries[0].elements['title'].text
email = entries[0].elements['author/email'].text
name = entries[0].elements['author/name'].text
[ title, email, name, entries.length ]
end
require 'net/https'
require 'rexml/document'
require 'timeout'
begin
timeout(2) do
username = "[email protected]"
password = "p4ssw0rd"
first = gmail_check(username, password)
if first
title, email, name, count = first
user, domain = email.split('@')
puts("(#{count}) #{user}:#{title}")
end
end
rescue Timeout::Error
end
```
Battery status checker in Ruby. Adapted for dwm from [wmii-ruby standard plugin](http://eigenclass.org/hiki/ruby-wmii+FAQ)
*/home/marko/bin/batstat.rb* (updated to use acpi for wider support)
```bash
#!/usr/bin/ruby
fd = IO.popen("/usr/bin/acpi")
acpi_status = fd.readlines.to_s.chomp
fd.close
status = '='
status = '^' if acpi_status =~ /harging/
status = 'v' if acpi_status =~ /ischarging/
percentage = /\d+(?=%)/.match(acpi_status)[0].to_i
if acpi_status =~ /ischarging/ && percentage <= 5
system("echo 'Critical battery' | xmessage -center -buttons quit:0 -default quit -file - &")
elsif acpi_status =~ /ischarging/ && percentage <= 8
system("echo 'Low battery' | xmessage -center -buttons quit:0 -default quit -file - &")
end
puts status + percentage.to_s + "%" + status
```
Then finally the status bar, which is run from *.xinitrc*.
*/home/marko/bin/status*
```bash
#!/bin/bash
echo "$(cat ~/tmp/mail) | $(date +"w%U %d.%m.%Y %R") | $(ruby ~/bin/batstat.rb)"
```
*/home/marko/.xinitrc*
```bash
xscreensaver-command -exit
xscreensaver -no-splash &
while true
do
xsetroot -name "$(status)"
sleep 1m
done &
xrandr --output VGA --mode 1920x1200 --right-of LVDS
#xrandr --output VGA --mode 1920x1080 --left-of LVDS
exec dwm
```