From c5b9c910ff735afd93aae210119d17db272fcc86 Mon Sep 17 00:00:00 2001 From: Adam Sanderson Date: Wed, 8 Dec 2010 19:46:59 -0800 Subject: [PATCH] Honor XDG Base Directory Specification if the user has XDG_CONFIG_HOME defined. --- bin/qw | 4 ++-- lib/qwandry.rb | 16 ++++++++++++++++ lib/qwandry/launcher.rb | 8 +++++--- qwandry.gemspec | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/bin/qw b/bin/qw index 99c961a..a927204 100755 --- a/bin/qw +++ b/bin/qw @@ -34,9 +34,9 @@ opts = OptionParser.new do |opts| end opts.on("--customize", "Create and edit files for customizing Qwandry") do - dir = ENV['HOME'] && ENV['HOME'] + '/.qwandry/' + dir = Qwandry.config_dir if !dir - puts "Home directory must be defined." + puts "HOME directory must be defined." exit(1) else FileUtils.mkdir(dir, :verbose=>true) unless File.exist?(dir) diff --git a/lib/qwandry.rb b/lib/qwandry.rb index 7108127..f1803cf 100644 --- a/lib/qwandry.rb +++ b/lib/qwandry.rb @@ -21,4 +21,20 @@ module Qwandry autoload :FlatRepository, "qwandry/flat_repository" autoload :LibraryRepository, "qwandry/library_repository" autoload :Package, "qwandry/package" +end + +def Qwandry.config_dir + subdir = '/.qwandry/' + + case + # If available, use XDG_CONFIG_HOME + # http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + when ENV['XDG_CONFIG_HOME'] then File.join(ENV['XDG_CONFIG_HOME'], subdir) + + # Otherwise fallback to qwandry's default and use the standard home dir + when ENV['HOME'] then File.join(ENV['HOME'], subdir) + + # If HOME isn't defined, all bets are off. + else nil + end end \ No newline at end of file diff --git a/lib/qwandry/launcher.rb b/lib/qwandry/launcher.rb index 2b1d4f3..8c8f818 100644 --- a/lib/qwandry/launcher.rb +++ b/lib/qwandry/launcher.rb @@ -95,9 +95,11 @@ module Qwandry end def custom_configuration! - custom_path = ENV['HOME'] && ENV['HOME'] + '/.qwandry/init.rb' - if File.exist? custom_path - eval IO.read(custom_path) + if config_dir = Qwandry.config_dir + custom_path = File.join(config_dir, 'init.rb') + if File.exist?(custom_path) + eval IO.read(custom_path) + end end end diff --git a/qwandry.gemspec b/qwandry.gemspec index 58c3e71..f394e0c 100644 --- a/qwandry.gemspec +++ b/qwandry.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.name = %q{qwandry} - s.version = "0.1.0" + s.version = "0.0.2" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Adam Sanderson"]