wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

wmiirc (1760B)


      1 #!/usr/bin/env ruby
      2 #
      3 # Bootloader for wmii configuration.
      4 #
      5 #--
      6 # Copyright protects this work.
      7 # See LICENSE file for details.
      8 #++
      9 
     10 # create a logger to aid debugging
     11 require 'logger'
     12 LOG = Logger.new(__FILE__ + '.log', 5)
     13 
     14 class << LOG
     15   # emulate IO.write
     16   alias write <<
     17 
     18   def flush
     19     # ignore
     20   end
     21 end
     22 
     23 # capture standard output in logger
     24 $stdout = $stderr = LOG
     25 
     26 begin
     27   LOG.info 'birth'
     28 
     29   # load configuration library
     30     def find_config file
     31       base_dirs = ENV['WMII_CONFPATH'].to_s.split(/:+/)
     32       ruby_dirs = base_dirs.map {|dir| File.join(dir, 'ruby') }
     33 
     34       Dir["{#{base_dirs.zip(ruby_dirs).join(',')}}/#{file}"].first
     35     end
     36 
     37     require find_config('config.rb')
     38 
     39   # terminate any existing wmiirc
     40     fs.event.write 'Start wmiirc'
     41 
     42     event 'Start' do |arg|
     43       exit if arg == 'wmiirc'
     44     end
     45 
     46   # apply user configuration
     47     load_config find_config('config.yaml')
     48 
     49   # setup tag bar (buttons that correspond to views)
     50     fs.lbar.clear
     51     tags.each {|t| event 'CreateTag', t }
     52     event 'FocusTag', curr_tag
     53 
     54   # register key bindings
     55     fs.keys.write keys.join("\n")
     56     event('Key') {|*a| key(*a) }
     57 
     58   # the main event loop
     59     fs.event.each_line do |line|
     60       line.split("\n").each do |call|
     61         name, args = call.split(' ', 2)
     62 
     63         argv = args.to_s.split(' ')
     64         event name, *argv
     65       end
     66     end
     67 
     68 rescue SystemExit
     69   # ignore it; the program wants to terminate
     70 
     71 rescue Exception => e
     72   LOG.error e
     73 
     74   # allow the user to rescue themselves
     75   system '@TERMINAL@ &'
     76 
     77   IO.popen('xmessage -nearmouse -file - -buttons Recover,Ignore -print', 'w+') do |f|
     78     f.puts e.inspect, e.backtrace
     79     f.close_write
     80 
     81     if f.read.chomp == 'Recover'
     82       reload_config
     83     end
     84   end
     85 
     86 ensure
     87   LOG.info 'death'
     88 end