Load OptionParser defaults from XDG and Haiku standards
This commit is contained in:
parent
970a25b104
commit
7e72ce0f73
@ -1806,13 +1806,26 @@ XXX
|
|||||||
# is not present. Returns whether successfully loaded.
|
# is not present. Returns whether successfully loaded.
|
||||||
#
|
#
|
||||||
# +filename+ defaults to basename of the program without suffix in a
|
# +filename+ defaults to basename of the program without suffix in a
|
||||||
# directory ~/.options.
|
# directory ~/.options, then the basename with '.options' suffix
|
||||||
|
# under XDG and Haiku standard places.
|
||||||
#
|
#
|
||||||
def load(filename = nil)
|
def load(filename = nil)
|
||||||
begin
|
unless filename
|
||||||
filename ||= File.expand_path(File.basename($0, '.*'), '~/.options')
|
basename = File.basename($0, '.*')
|
||||||
rescue
|
return true if load(File.expand_path(basename, '~/.options')) rescue nil
|
||||||
return false
|
basename << ".options"
|
||||||
|
return [
|
||||||
|
# XDG
|
||||||
|
ENV['XDG_CONFIG_HOME'],
|
||||||
|
'~/.config',
|
||||||
|
*ENV['XDG_CONFIG_DIRS']&.split(File::PATH_SEPARATOR),
|
||||||
|
|
||||||
|
# Haiku
|
||||||
|
'~/config/settings',
|
||||||
|
].any? {|dir|
|
||||||
|
next if !dir or dir.empty?
|
||||||
|
load(File.expand_path(basename, dir)) rescue nil
|
||||||
|
}
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
parse(*IO.readlines(filename).each {|s| s.chomp!})
|
parse(*IO.readlines(filename).each {|s| s.chomp!})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user