Honor XDG Base Directory Specification if the user has XDG_CONFIG_HOME defined.
This commit is contained in:
parent
e044eebe28
commit
c5b9c910ff
4
bin/qw
4
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)
|
||||
|
@ -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
|
@ -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
|
||||
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user