life.i.think -

s.rb: X60, Compiz, & Xrandr.
Scribbled on July 17th. 0 comments.

Continuing with Ruby scripts that should probably be written in Bash, here’s one for the eyecandy inclined.

Situation:

  • You are running an X stack that supports xrandr 1.2.
  • You are running Compiz (Fusion).
  • You want to switch back and forth between an external monitor, and your laptop’s display.

A couple of notes. Unfortunately, you cannot trigger an xrandr script on VGA plug/unplug events (yet). See this post. Also, if you are not running an accelerated desktop, or your 2 monitors fit within the bounds defined by a few X components (see this post), you can use your laptop as a secondary monitor.

For now, I’m just toggling between my two monitors via this small Ruby script.


#!/usr/bin/env ruby

def lappy; exec "xrandr --output VGA --off --output LVDS --auto";  end
def external; exec "xrandr --output LVDS --off --output VGA --auto"; end

case ARGV.first
  when 'l' then lappy
  when 'e' then external
  else
    external if `xrandr -q`.include?('VGA connected')
    lappy
  end

Download.

And before all you MacHeads out there smile to yourselves about all this work; You thought I forgot about you! I so vary rarely tinker with my desktop setup. This truly is the oddity! Oh, and http://twitter.com/blaine/statuses/153159902

f.rb: An awk script.
Scribbled on July 12th. 5 comments.

Also known as “the most the most useful piece of software [someone else] wrote in [a] calendar year,” rewritten.

Today Mark Dominus blogged about f, a wholly fantastic and tiny Perl script that changes:

ps aux | awk ‘{print $2}’ to ps aux | f 2.

Of course there’s the deeply embedded urge of every geek to take something like this and reproduce it in all possible languages (plus there was a syntax error running the Perl script on my end), so here we have it in Ruby!


#!/usr/bin/ruby

($stderr.print "f.rb usage: fieldnumber\n"; exit) if ARGV.empty?
$stdin.each { |l| puts l.split[ARGV.first.to_i-1] }

Download.