mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
config/default: add support for $XDG_CACHE_HOME for history
Fixes #1316 (support XDG Base Directory Specification)
This commit is contained in:
parent
f47120f538
commit
15e1fc929e
2 changed files with 14 additions and 6 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue