Skip to content

Commit

Permalink
Add XDG support for history file (ruby#1031)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jgarber623 committed Dec 31, 2023
1 parent 9de0ff4 commit d8ef53d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/debug/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,20 @@ def history
end

def history_file
history_file = CONFIG[:history_file]
path =
if !CONFIG[:history_file].empty? && File.exist?(File.expand_path(CONFIG[:history_file]))
CONFIG[:history_file]
elsif (xdg_home = ENV['XDG_DATA_HOME'])
File.join(xdg_home, 'rdbg', 'history')
else
'~/.rdbg_history'
end

if !history_file.empty?
File.expand_path(history_file)
else
history_file
end
path = File.expand_path(path)

FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(path)

path
end

FH = "# Today's OMIKUJI: "
Expand Down

0 comments on commit d8ef53d

Please sign in to comment.