diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2018-11-03 18:57:17 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-03 18:57:17 +0800 |
commit | a61115ceba243e0f2eb719b9385be34c3cad6f79 (patch) | |
tree | 5cf60b876cb1b093b95ead41b7b7f506f98c9c73 | |
parent | f47120f53870ccf883a1545ae74493046d6f4466 (diff) | |
parent | 15e1fc929ed84c161abc5afc9be73488a41df397 (diff) | |
download | pry-a61115ceba243e0f2eb719b9385be34c3cad6f79.tar.gz |
Merge pull request #1844 from pry/1316-xdg-history
config/default: add support for $XDG_CACHE_HOME for history
-rw-r--r-- | lib/pry/config/default.rb | 17 | ||||
-rw-r--r-- | lib/pry/history.rb | 3 |
2 files changed, 14 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..8f1fec55 100644 --- a/lib/pry/history.rb +++ b/lib/pry/history.rb @@ -136,6 +136,9 @@ class Pry if defined?(@history_file) @history_file else + unless File.exist?(history_file_path) + FileUtils.mkdir_p(File.dirname(history_file_path)) + end @history_file = File.open(history_file_path, 'a', 0600).tap do |file| file.sync = true end |