Honor XDG Base Directory Specification if the user has XDG_CONFIG_HOME defined.

This commit is contained in:
Adam Sanderson 2010-12-08 19:46:59 -08:00
parent e044eebe28
commit c5b9c910ff
4 changed files with 24 additions and 6 deletions

4
bin/qw
View File

@ -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)

View File

@ -22,3 +22,19 @@ module Qwandry
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

View File

@ -95,11 +95,13 @@ module Qwandry
end
def custom_configuration!
custom_path = ENV['HOME'] && ENV['HOME'] + '/.qwandry/init.rb'
if File.exist? 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
end
end

View File

@ -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"]