From d8ef53d6bea85b9b0c87602f117786fb807d2643 Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Sat, 30 Dec 2023 22:32:38 -0500 Subject: [PATCH 1/3] Add XDG support for history file (#1031) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit implements XDG directory support for this gem's history file in accordance with the rules outlined in #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: https://github.com/ruby/debug/issues/1031#issuecomment-1855128422 --- lib/debug/console.rb | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/debug/console.rb b/lib/debug/console.rb index 53545e5e9..bc37276fd 100644 --- a/lib/debug/console.rb +++ b/lib/debug/console.rb @@ -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: " From bba01c7531d45ef7e008b5b46c4140c1638887a0 Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Sat, 30 Dec 2023 22:35:25 -0500 Subject: [PATCH 2/3] Add XDG support for rdbgrc file (#1031) This commit implements XDG directory support for this gem's `.rdbgrc` configuration file in accordance with the rules outlined in #1031: > 1. prefer `~/.rdbgrc` if present, > 2. else, `$XDG_CONFIG_HOME/rdbg/config` if `$XDG_CONFIG_HOME` is set > and `$XDG_CONFIG_HOME/rdbg/config` is present, > 3. else, no customized user configuration See: https://github.com/ruby/debug/issues/1031#issuecomment-1855128422 --- lib/debug/session.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/debug/session.rb b/lib/debug/session.rb index f76f9dc6d..136bbfc4d 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -2293,11 +2293,19 @@ def skip? end def self.load_rc - [[File.expand_path('~/.rdbgrc'), true], - [File.expand_path('~/.rdbgrc.rb'), true], - # ['./.rdbgrc', true], # disable because of security concern - [CONFIG[:init_script], false], - ].each{|(path, rc)| + rc_file_paths = [ + [File.expand_path('~/.rdbgrc'), true], + [File.expand_path('~/.rdbgrc.rb'), true], + # ['./.rdbgrc', true], # disable because of security concern + ] + + if (xdg_home = ENV["XDG_CONFIG_HOME"]) + rc_file_paths << [File.expand_path(File.join(xdg_home, "rdbg", "config")), true] + end + + rc_file_paths << [CONFIG[:init_script], false] + + rc_file_paths.each{|(path, rc)| next unless path next if rc && CONFIG[:no_rc] # ignore rc From 55f66240abf152a91a42df8aa4d05e2a25387bdd Mon Sep 17 00:00:00 2001 From: Jason Garber Date: Fri, 15 Mar 2024 16:20:20 -0400 Subject: [PATCH 3/3] Support config.rb in XDG config path (#1031) --- lib/debug/session.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/debug/session.rb b/lib/debug/session.rb index 136bbfc4d..be4a63b66 100644 --- a/lib/debug/session.rb +++ b/lib/debug/session.rb @@ -2301,6 +2301,7 @@ def self.load_rc if (xdg_home = ENV["XDG_CONFIG_HOME"]) rc_file_paths << [File.expand_path(File.join(xdg_home, "rdbg", "config")), true] + rc_file_paths << [File.expand_path(File.join(xdg_home, "rdbg", "config.rb")), true] end rc_file_paths << [CONFIG[:init_script], false]