Skip to content

fix hitory file path #1146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ config set no_color true
* `RUBY_DEBUG_INIT_SCRIPT` (`init_script`): debug command script path loaded at first stop
* `RUBY_DEBUG_COMMANDS` (`commands`): debug commands invoked at first stop. Commands should be separated by `;;`
* `RUBY_DEBUG_NO_RC` (`no_rc`): ignore loading ~/.rdbgrc(.rb) (default: false)
* `RUBY_DEBUG_HISTORY_FILE` (`history_file`): history file (default: ~/.rdbg_history)
* `RUBY_DEBUG_HISTORY_FILE` (`history_file`): history file (default: $XDG_STATE_HOME/rdbg/history)
* `RUBY_DEBUG_SAVE_HISTORY` (`save_history`): maximum save history lines (default: 10000)

* REMOTE
Expand Down
2 changes: 1 addition & 1 deletion lib/debug/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module DEBUGGER__
init_script: ['RUBY_DEBUG_INIT_SCRIPT', "BOOT: debug command script path loaded at first stop"],
commands: ['RUBY_DEBUG_COMMANDS', "BOOT: debug commands invoked at first stop. Commands should be separated by `;;`"],
no_rc: ['RUBY_DEBUG_NO_RC', "BOOT: ignore loading ~/.rdbgrc(.rb)", :bool, "false"],
history_file: ['RUBY_DEBUG_HISTORY_FILE',"BOOT: history file", :string, "~/.rdbg_history"],
history_file: ['RUBY_DEBUG_HISTORY_FILE',"BOOT: history file (default: $XDG_STATE_HOME/rdbg/history)", :string, nil],
save_history: ['RUBY_DEBUG_SAVE_HISTORY',"BOOT: maximum save history lines", :int, "10000"],

# remote setting
Expand Down
26 changes: 12 additions & 14 deletions lib/debug/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,24 @@ def history
end

def 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

path = File.expand_path(path)
case
when (path = CONFIG[:history_file]) && !path.empty?
path = File.expand_path(path)
when (path = File.expand_path("~/.rdbg_history")) && File.exist?(path) # for compatibility
# path
else
state_dir = ENV['XDG_STATE_HOME'] || File.join(Dir.home, '.local', 'state')
path = File.join(File.expand_path(state_dir), 'rdbg', 'history')
end

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

path
end

FH = "# Today's OMIKUJI: "

def read_history_file
if history && File.exist?(path = history_file)
if history && File.exist?(path = history_file())
f = (['', 'DAI-', 'CHU-', 'SHO-'].map{|e| e+'KICHI'}+['KYO']).sample
# Read history file and scrub invalid characters to prevent encoding errors
lines = File.readlines(path).map(&:scrub)
Expand All @@ -195,12 +193,12 @@ def load_history_if_not_loaded
def deactivate
if history && @init_history_lines
added_records = history.to_a[@init_history_lines .. -1]
path = history_file
path = history_file()
max = CONFIG[:save_history]

if !added_records.empty? && !path.empty?
orig_records = read_history_file
open(history_file, 'w'){|f|
open(history_file(), 'w'){|f|
(orig_records + added_records).last(max).each{|line|
# Use scrub to handle encoding issues gracefully
scrubbed_line = line.scrub.strip
Expand Down
Loading