From 64e1442d93b5560341b4bf79a905784d80a44ff9 Mon Sep 17 00:00:00 2001 From: fbt Date: Thu, 29 Sep 2016 16:01:35 +0300 Subject: [PATCH] A config file location option --- moltenbar | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/moltenbar b/moltenbar index 0c59369..887ae0b 100755 --- a/moltenbar +++ b/moltenbar @@ -61,12 +61,6 @@ class DoSystem < Worker end end -class ::String - def erb - return ERB.new(self).result - end -end - module Modules @modules = {} @@ -88,7 +82,7 @@ class Template @config = config @panel_data = data - return ERB.new(@template).result(binding) + return ERB.new(@template).result(binding()) end end @@ -107,9 +101,19 @@ end require 'erb' require 'yaml' +require 'optparse' workers = [] panel_data = {} +options = {} + +OptionParser.new do |opts| + opts.banner = "Usage: moltenvar [-c]" + + opts.on("-cCONFIG", "--config=CONFIG") do |v| + options[:config_file] = v + end +end.parse! if ENV["XDG_CONFIG_HOME"] == nil conf_dir = ENV["HOME"] + "/.config/moltenbar" @@ -117,15 +121,14 @@ else conf_dir = ENV["XDG_CONFIG_HOME"] + "/moltenbar" end -config_file = conf_dir + "/rc.yaml" -mod_dir = conf_dir + "/mod" +options[:config_file] ||= conf_dir + "/rc.yaml" -puts config_file +config = YAML.load_file(options[:config_file]) -config = YAML.load_file(config_file) +config['mod_dir'] ||= conf_dir + "/mod" for m in config['modules'] do - load("#{mod_dir}/#{m}") + load("#{config['mod_dir']}/#{m}") end pipe_r, pipe_w = IO.pipe