diff --git a/README.md b/README.md index 6e737499e..f429270b3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/debug/config.rb b/lib/debug/config.rb index 222e2a9d2..906b41f00 100644 --- a/lib/debug/config.rb +++ b/lib/debug/config.rb @@ -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 diff --git a/lib/debug/console.rb b/lib/debug/console.rb index 2c89f035f..ec860b423 100644 --- a/lib/debug/console.rb +++ b/lib/debug/console.rb @@ -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) @@ -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