Skip to content

Commit d8ef53d

Browse files
committed
Add XDG support for history file (ruby#1031)
This commit implements XDG directory support for this gem's history file in accordance with the rules outlined in ruby#1031: > For the history file: > > 1. prefer `~/.rdbg_history` if present, > 2. else, `$XDG_DATA_HOME/rdbg/history` if `$XDG_DATA_HOME` is set¹ > > ¹ There'd need to be a check for this file path. If it exists, great! > If not, create the path `$XDG_DATA_HOME/rdbg` and touch > `$XDG_DATA_HOME/rdbg/history`. See: ruby#1031 (comment)
1 parent 9de0ff4 commit d8ef53d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

lib/debug/console.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,20 @@ def history
153153
end
154154

155155
def history_file
156-
history_file = CONFIG[:history_file]
156+
path =
157+
if !CONFIG[:history_file].empty? && File.exist?(File.expand_path(CONFIG[:history_file]))
158+
CONFIG[:history_file]
159+
elsif (xdg_home = ENV['XDG_DATA_HOME'])
160+
File.join(xdg_home, 'rdbg', 'history')
161+
else
162+
'~/.rdbg_history'
163+
end
157164

158-
if !history_file.empty?
159-
File.expand_path(history_file)
160-
else
161-
history_file
162-
end
165+
path = File.expand_path(path)
166+
167+
FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(path)
168+
169+
path
163170
end
164171

165172
FH = "# Today's OMIKUJI: "

0 commit comments

Comments
 (0)