diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2018-11-03 16:16:04 +0800 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2018-11-03 16:16:04 +0800 |
commit | f07da4065343024294ac7e5138069d935c41e9c1 (patch) | |
tree | a0c668df008d72a96bae09fdab1e30dc3b0d50ee | |
parent | dec541b47f2bf171972ee5e2cf3c80ec2fecec1e (diff) | |
download | pry-1316-xdg-history.tar.gz |
config/default: add support for $XDG_CACHE_HOME for history1316-xdg-history
Fixes #1316
(support XDG Base Directory Specification)
-rw-r--r-- | lib/pry/config/default.rb | 17 | ||||
-rw-r--r-- | lib/pry/history.rb | 1 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/pry/config/default.rb b/lib/pry/config/default.rb index 7d441e21..0821f576 100644 --- a/lib/pry/config/default.rb +++ b/lib/pry/config/default.rb @@ -119,12 +119,17 @@ class Pry }, history: proc { Pry::Config.from_hash({should_save: true, should_load: true}, nil).tap do |history| - history.file = File.expand_path("~/.pry_history") rescue nil - if history.file.nil? - self.should_load_rc = false - history.should_save = false - history.should_load = false - end + history_file = + if File.exist?(File.expand_path('~/.pry_history')) + '~/.pry_history' + elsif ENV.key?('XDG_CACHE_HOME') && ENV['XDG_CACHE_HOME'] != '' + # See XDG Base Directory Specification at + # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html + ENV['XDG_CACHE_HOME'] + '/pry/pry_history' + else + '~/.cache/pry/pry_history' + end + history.file = File.expand_path(history_file) end }, exec_string: proc { diff --git a/lib/pry/history.rb b/lib/pry/history.rb index b40dac50..0e7b1f37 100644 --- a/lib/pry/history.rb +++ b/lib/pry/history.rb @@ -136,6 +136,7 @@ class Pry if defined?(@history_file) @history_file else + FileUtils.mkdir_p(File.dirname(history_file_path)) @history_file = File.open(history_file_path, 'a', 0600).tap do |file| file.sync = true end |