wmiirc-rumai

git clone git://oldgit.suckless.org/wmiirc-rumai/
Log | Files | Refs | README | LICENSE

commit 2d2d0d31382aefd92c30d70387e271d9ae7826f9
parent 7b96cf8f1b8191cd9ca6e44fc9743312ff4a4532
Author: Suraj N. Kurapati <sunaku@gmail.com>
Date:   Mon, 19 Jan 2009 21:30:30 -0800

clean up

Diffstat:
README | 20++++++++------------
wmiirc | 189++++++++++++++++++++++++++++++++++++++++---------------------------------------
wmiirc-config.rb | 40++++++++++------------------------------
3 files changed, 113 insertions(+), 136 deletions(-)

diff --git a/README b/README @@ -1,20 +1,16 @@ -wmiirc: wmii configuration in Ruby -================================== +This is my Ruby-based wmii configuration, explained in this article: -This is my wmii configuration in Ruby [1]. It currently only works with -wmii-snap20070516, but I will work on upgrading it to wmii-3.6 soon. + http://snk.tuxfamily.org/web/2006-07-01-wmii-3-1-configuration-in-ruby.html -If you have any questions or suggestions, e-mail me at <SNK at GNA dot ORG>. +Dependencies: -Cheers. + gem install rumai librmpd -[1] http://rassmalog.rubyforge.org/blog/2006-07-01-wmii-3-1-configuration-in-ruby.html +Installation: + git clone git://github.com/sunaku/wmiirc.git ~/.wmii-hg -Setup instructions ------------------- + chmod +x ~/.wmii-hg/wmiirc -1. Install the Rumai library: http://rumai.rubyforge.org - -2. Adjust the $: (load path) variable at the top of the wmiirc file. + ~/.wmii-hg/wmiirc diff --git a/wmiirc b/wmiirc @@ -1,111 +1,112 @@ #!/usr/bin/ruby -w # Loader for ruby-based wmii configuration. -# load the wmii-irb library -$: << '/home/sun/src/rumai/lib' -require 'rumai' -include Rumai +# load the Ruby interface to wmii + require 'rubygems' + gem 'rumai', '~> 2' + require 'rumai' + include Rumai # create a logger to aid debugging -require 'logger' -LOG = Logger.new(__FILE__ + '.log', 5) + require 'logger' + LOG = Logger.new(__FILE__ + '.log', 5) -unless $DEBUG - class << LOG - alias write << # emulate IO.write + unless $DEBUG + class << LOG + # emulate IO.write + alias write << - def flush - # ignore + def flush + # ignore + end end - end - - # capture standard output in logger - $stdout = $stderr = LOG -end + # capture standard output in logger + $stdout = $stderr = LOG + end LOG.info "birth" begin - ## - # - # Miniature DSL to ease configuration. - # - ## - - class Handler < Hash - def initialize - super {|h,k| h[k] = [] } - end + # miniature DSL to ease configuration + class Handler < Hash + def initialize + super {|h,k| h[k] = [] } + end - # When a block is given, registers a handler for the given key. - # Otherwise, executes all registered handlers for the given key. - def handle aKey, *aArgs, &aBlock - if block_given? - self[aKey] << aBlock + # When a block is given, registers a handler for the given key. + # Otherwise, executes all registered handlers for the given key. + def handle aKey, *aArgs, &aBlock + if block_given? + self[aKey] << aBlock - elsif key? aKey - self[aKey].each do |block| - block.call(*aArgs) + elsif key? aKey + self[aKey].each do |block| + block.call(*aArgs) + end end end end - end - EVENTS = Handler.new - ACTIONS = Handler.new - KEYS = Handler.new + EVENTS = Handler.new + ACTIONS = Handler.new + KEYS = Handler.new - def event *a, &b - EVENTS.handle(*a, &b) - end + def event *a, &b + EVENTS.handle(*a, &b) + end - def action *a, &b - ACTIONS.handle(*a, &b) - end + def action *a, &b + ACTIONS.handle(*a, &b) + end - def key *a, &b - KEYS.handle a.map {|k| k.flatten.join('-') rescue k }.join(','), &b - end + def key *a, &b + KEYS.handle a.map {|k| k.flatten.join('-') rescue k }.join(','), &b + end + def unevent *a + EVENTS.delete(*a) + end - ## - # - # Utility functions - # - ## + def unaction *a + ACTIONS.delete(*a) + end - # Shows a menu with the given items and returns the chosen - # item. If nothing was chosen, then *nil* is returned. - def show_menu aChoices, aPrompt = nil - cmd = "dmenu -b -fn #{WMII_FONT.inspect} " << - %w[-nf -nb -sf -sb].zip( - Color::NORMAL.split[0,2] + Color::FOCUSED.split[0,2] - ).flatten.map {|s| s.inspect}.join(' ') + def unkey *a + KEYS.delete(*a) + end - cmd << " -p #{aPrompt.to_s.inspect}" if aPrompt + # utility methods - IO.popen cmd, 'r+' do |menu| - menu.puts aChoices - menu.close_write + # Shows a menu with the given items and returns the chosen + # item. If nothing was chosen, then *nil* is returned. + def show_menu aChoices, aPrompt = nil + cmd = "dmenu -b -fn #{WMII_FONT.inspect} " << + %w[-nf -nb -sf -sb].zip( + Color::NORMAL.split[0,2] + Color::FOCUSED.split[0,2] + ).flatten.map {|s| s.inspect}.join(' ') - choice = menu.read - choice unless choice.empty? - end - end + cmd << " -p #{aPrompt.to_s.inspect}" if aPrompt + IO.popen cmd, 'r+' do |menu| + menu.puts aChoices + menu.close_write - require 'pathname' + choice = menu.read + choice unless choice.empty? + end + end - # Returns the names of programs present in the given directories. - def find_programs *aDirs - aDirs.flatten.map do |d| - Pathname.new(d).expand_path.children rescue [] - end.flatten.map do |f| - f.basename.to_s if f.file? and f.executable? - end.compact.uniq.sort - end + require 'pathname' + # Returns the names of programs present in the given directories. + def find_programs *aDirs + aDirs.flatten.map do |d| + Pathname.new(d).expand_path.children rescue [] + end.flatten.map do |f| + f.basename.to_s if f.file? and f.executable? + end.compact.uniq.sort + end # terminate existing instances of this program fs.event.write 'Start wmiirc' @@ -118,33 +119,33 @@ begin load File.join(File.dirname(__FILE__), 'wmiirc-config.rb') # populate lbar with buttons for every tag - bar = fs.lbar - bar.clear + bar = fs.lbar + bar.clear - tags.each do |tag| - color = (tag == curr_tag) ? Color::FOCUSED : Color::NORMAL + tags.each do |tag| + color = (tag == curr_tag) ? Color::FOCUSED : Color::NORMAL - btn = bar[tag] - btn.create - btn.write "#{color} #{tag}" - end + btn = bar[tag] + btn.create + btn.write "#{color} #{tag}" + end # enable keyboard shortcuts - fs.keys.write KEYS.keys.join("\n") + fs.keys.write KEYS.keys.join("\n") - event :Key do |*args| - key(*args) - end + event :Key do |*args| + key(*args) + end # the main event loop - fs.event.each_line do |line| - line.split("\n").each do |event| - type, parms = event.split(' ', 2) + fs.event.each_line do |line| + line.split("\n").each do |event| + type, parms = event.split(' ', 2) - args = parms.split(' ') rescue [] - event type.to_sym, *args + args = parms.split(' ') rescue [] + event type.to_sym, *args + end end - end rescue => e LOG.error e diff --git a/wmiirc-config.rb b/wmiirc-config.rb @@ -80,8 +80,7 @@ fs.tagrules.write <<EOF /.*/ -> 1 EOF -# Events - +# events event :CreateTag do |tag| bar = fs.lbar[tag] bar.create @@ -158,9 +157,7 @@ EOF end end - -# Actions - +# actions action :rehash do @programMenu = find_programs ENV['PATH'].squeeze(':').split(':') @actionMenu = find_programs File.dirname(__FILE__) @@ -234,11 +231,8 @@ EOF ] end - -# Key bindings - +# keyboard shortcuts # focusing / showing - # focus client at left key Key::FOCUS + Key::LEFT do curr_view.ctl.write 'select left' rescue nil @@ -310,9 +304,7 @@ EOF next_view.focus end - # sending / moving - key Key::SEND + Key::LEFT do grouping.each do |c| c.send :left @@ -393,9 +385,7 @@ EOF end end - # zooming / sizing - ZOOMED_SUFFIX = /~(\d+)$/ # Sends grouped clients to temporary view. @@ -414,6 +404,7 @@ EOF v = View.new dst v.focus v.arrange_in_grid + #if c = grouping.shift then c.focus unless c.focus? end end # Sends grouped clients back to their original view. @@ -439,9 +430,7 @@ EOF end end - # client grouping - # include/exclude the currently focused client from the grouping key Key::GROUP + 'g' do curr_client.toggle_group @@ -501,9 +490,7 @@ EOF Rumai.ungroup end - # visual arrangement - key Key::ARRANGE + 't' do curr_view.arrange_as_larswm end @@ -516,9 +503,7 @@ EOF curr_view.arrange_in_diamond end - # interactive menu - # launch an internal action by choosing from a menu key Key::MENU + 'i' do if choice = show_menu(@actionMenu + ACTIONS.keys, 'run action:') @@ -555,9 +540,7 @@ EOF end end - # external programs - require 'fileutils' # Open a new terminal and set its working directory @@ -661,7 +644,6 @@ EOF # wmii-2 style client detaching - DETACHED_TAG = '|' # Detach the current grouping from the current view. @@ -686,9 +668,7 @@ EOF end end - # number keys - 10.times do |i| # focus the {i}'th view key Key::FOCUS + i.to_s do @@ -713,9 +693,7 @@ EOF end end - # alphabet keys - # focus the view whose name begins with an alphabet key ('a'..'z').each do |k| key Key::VIEW + k do @@ -725,8 +703,10 @@ EOF end end +# wallpaper + system "xsetroot -solid #{Color::BACKGROUND.inspect} &" + system 'sh ~/.fehbg &' # set desktop wallpaper -# Misc Setup -system "xsetroot -solid #{Color::BACKGROUND.inspect} &" -action :status -action :rehash +# bootstrap + action :status + action :rehash