Skip to content
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

Support XDG directories for config and history files #1055

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
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
19 changes: 14 additions & 5 deletions lib/debug/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2293,11 +2293,20 @@ 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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you need config.rb here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This change should support both ${XDG_CONFIG_HOME}/rdbg/config and ${XDG_CONFIG_HOME}/rdbg/config.rb. I'll make that update.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ko1 Thank you again for the feedback. I've added support for config.rb in this path in 55f6624.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

rc_file_paths << [File.expand_path(File.join(xdg_home, "rdbg", "config.rb")), 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

Expand Down
Loading