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
|
end
|
||||||
|
|
||||||
opts.on("--customize", "Create and edit files for customizing Qwandry") do
|
opts.on("--customize", "Create and edit files for customizing Qwandry") do
|
||||||
dir = ENV['HOME'] && ENV['HOME'] + '/.qwandry/'
|
dir = Qwandry.config_dir
|
||||||
if !dir
|
if !dir
|
||||||
puts "Home directory must be defined."
|
puts "HOME directory must be defined."
|
||||||
exit(1)
|
exit(1)
|
||||||
else
|
else
|
||||||
FileUtils.mkdir(dir, :verbose=>true) unless File.exist?(dir)
|
FileUtils.mkdir(dir, :verbose=>true) unless File.exist?(dir)
|
||||||
|
|
|
@ -22,3 +22,19 @@ module Qwandry
|
||||||
autoload :LibraryRepository, "qwandry/library_repository"
|
autoload :LibraryRepository, "qwandry/library_repository"
|
||||||
autoload :Package, "qwandry/package"
|
autoload :Package, "qwandry/package"
|
||||||
end
|
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,11 +95,13 @@ module Qwandry
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_configuration!
|
def custom_configuration!
|
||||||
custom_path = ENV['HOME'] && ENV['HOME'] + '/.qwandry/init.rb'
|
if config_dir = Qwandry.config_dir
|
||||||
if File.exist? custom_path
|
custom_path = File.join(config_dir, 'init.rb')
|
||||||
|
if File.exist?(custom_path)
|
||||||
eval IO.read(custom_path)
|
eval IO.read(custom_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{qwandry}
|
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.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
||||||
s.authors = ["Adam Sanderson"]
|
s.authors = ["Adam Sanderson"]
|
||||||
|
|
Loading…
Reference in New Issue