diff options
author | Nobuyoshi Nakada <[email protected]> | 2019-05-06 15:30:44 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2019-05-06 15:30:44 +0900 |
commit | 7e72ce0f734113e3e215a74b440092443e957d45 (patch) | |
tree | 7f42af821bd332680518ff20d36e2e462b3c435d /lib/optparse.rb | |
parent | 970a25b10415bc3735e6e3c165e167e6abc3d7f4 (diff) |
Load OptionParser defaults from XDG and Haiku standards
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r-- | lib/optparse.rb | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb index 5cdcabf4a7..9937e2500d 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -1806,13 +1806,26 @@ XXX # is not present. Returns whether successfully loaded. # # +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) - begin - filename ||= File.expand_path(File.basename($0, '.*'), '~/.options') - rescue - return false + unless filename + basename = File.basename($0, '.*') + return true if load(File.expand_path(basename, '~/.options')) rescue nil + 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 begin parse(*IO.readlines(filename).each {|s| s.chomp!}) |