-
Notifications
You must be signed in to change notification settings - Fork 121
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
Fix irb_history saved to current directory #901
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
78124de
Always save irb_history in HOME or XDG_CONFIG_HOME
tompng 1e89200
Remove IRB.conf[:RC_NAME_GENERATOR] because it's not configurable
tompng 4d96c35
remove rc_file_test because it is tested with rc_files, remove useles…
tompng d47e6f2
Make internal irbrc searching method private
tompng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,42 +395,54 @@ def IRB.parse_opts(argv: ::ARGV) | |
# Run the config file | ||
def IRB.run_config | ||
if @CONF[:RC] | ||
rc_files.each do |rc| | ||
# Because rc_file always returns `HOME/.irbrc` even if no rc file is present, we can't warn users about missing rc files. | ||
# Otherwise, it'd be very noisy. | ||
load rc if File.exist?(rc) | ||
irbrc_files.each do |rc| | ||
load rc | ||
rescue StandardError, ScriptError => e | ||
warn "Error loading RC file '#{rc}':\n#{e.full_message(highlight: false)}" | ||
end | ||
end | ||
end | ||
|
||
IRBRC_EXT = "rc" | ||
def IRB.rc_file(ext = IRBRC_EXT) | ||
warn "rc_file is deprecated, please use rc_files instead." | ||
rc_files(ext).first | ||
end | ||
|
||
def IRB.rc_files(ext = IRBRC_EXT) | ||
if !@CONF[:RC_NAME_GENERATOR] | ||
@CONF[:RC_NAME_GENERATOR] ||= [] | ||
existing_rc_file_generators = [] | ||
def IRB.prepare_rc_name_generators | ||
return if @existing_rc_name_generators | ||
|
||
rc_file_generators do |rcgen| | ||
@CONF[:RC_NAME_GENERATOR] << rcgen | ||
existing_rc_file_generators << rcgen if File.exist?(rcgen.call(ext)) | ||
@existing_rc_name_generators = [] | ||
@irbrc_files = [] | ||
rc_file_generators do |rcgen| | ||
irbrc = rcgen.call(IRBRC_EXT) | ||
if File.exist?(irbrc) | ||
@irbrc_files << irbrc | ||
@existing_rc_name_generators << rcgen | ||
end | ||
end | ||
generate_current_dir_irbrc_files.each do |irbrc| | ||
@irbrc_files << irbrc if File.exist?(irbrc) | ||
end | ||
@irbrc_files.uniq! | ||
end | ||
|
||
if existing_rc_file_generators.any? | ||
@CONF[:RC_NAME_GENERATOR] = existing_rc_file_generators | ||
end | ||
def IRB.rc_file(ext) | ||
prepare_rc_name_generators | ||
|
||
# When irbrc exist in default location | ||
if (rcgen = @existing_rc_name_generators.first) | ||
return rcgen.call(ext) | ||
end | ||
|
||
@CONF[:RC_NAME_GENERATOR].map do |rc| | ||
rc_file = rc.call(ext) | ||
fail IllegalRCNameGenerator unless rc_file.is_a?(String) | ||
rc_file | ||
# When irbrc does not exist in default location | ||
rc_file_generators do |rcgen| | ||
return rcgen.call(ext) | ||
end | ||
|
||
# When HOME and XDG_CONFIG_HOME are not available | ||
nil | ||
end | ||
|
||
def IRB.irbrc_files | ||
prepare_rc_name_generators | ||
@irbrc_files | ||
end | ||
|
||
# enumerate possible rc-file base name generators | ||
|
@@ -446,13 +458,16 @@ def IRB.rc_file_generators | |
end | ||
if home = ENV["HOME"] | ||
yield proc{|rc| home+"/.irb#{rc}"} | ||
yield proc{|rc| home+"/.config/irb/irb#{rc}"} | ||
if xdg_config_home.nil? || xdg_config_home.empty? | ||
yield proc{|rc| home+"/.config/irb/irb#{rc}"} | ||
end | ||
end | ||
end | ||
|
||
# possible irbrc files in current directory | ||
def IRB.generate_current_dir_irbrc_files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make this private too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
current_dir = Dir.pwd | ||
yield proc{|rc| current_dir+"/.irb#{rc}"} | ||
yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"} | ||
yield proc{|rc| current_dir+"/_irb#{rc}"} | ||
yield proc{|rc| current_dir+"/$irb#{rc}"} | ||
%w[.irbrc irbrc _irbrc $irbrc].map { |file| "#{current_dir}/#{file}" } | ||
end | ||
|
||
# loading modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can declare this as private?
Also, I feel
prepare_irbrc_name_generators
is a clearer name.