#!/usr/bin/env ruby # ############################################################# # # file : shrc.rb # author : mathias gumz # copyr : copyright (c) 2005 by m. gumz # license : see LICENSE # # start : Sa 30 Apr 2005 00:45:33 CEST # ############################################################# # # about :reads in a rc-file in shell-syntax and provides # the result in a hash / dictionary # ############################################################# # # # class ShRcReader attr_reader(:opts, :filename, :comments, :assign) def initialize(filename, comments = '[#!]', assign = '=') @filename, @comments, @assign = filename, comments, assign @opts = { } File.open(@filename, 'r') { |f| f.readlines.each { |line| case line when /^#{comments}/, /^\s*$/ then next when /(\S+)\s*#{assign}(.*)/ then @opts[$1.strip] = $2.strip end } } end end if $0 == __FILE__ ARGV[0..ARGV.length].each { |arg| puts arg ShRcReader.new(arg).opts.each { |k, v| puts "#{k} => #{v}" } } end # # # ############################################################# # # #############################################################