Created
July 13, 2024 05:43
-
-
Save sczi/fc09268304578d0eaf729fe1eeab3853 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'open3' | |
require 'reline' | |
class Reline::LineEditor | |
private def perform_completion(list, _just_show_list) | |
_preposing, target, _postposing = retrieve_completion_block | |
namespace = IRB.CurrentContext.io.retrieve_doc_namespace(target) | |
namespace = namespace.first if namespace.is_a?(Array) | |
if namespace.nil? || !('A'..'Z').include?(namespace[0]) | |
namespace = IRB.conf[:__MAIN__] | |
namespace = namespace.class unless namespace.is_a? Class | |
namespace = namespace.to_s | |
end | |
namespace.sub!(/\..*?$/, '') | |
unless list.empty? | |
selection, status = Open3.capture2("fzf", "--query", target, | |
"--preview", "ri #{namespace}.$(echo {} | sed -e 's/^[^.]*\\.//')", | |
stdin_data: list.join("\n")) | |
insert_text(selection.rstrip.delete_prefix(target)) if status | |
end | |
end | |
end | |
# this just makes it autocomplete only when tab is pressed rather than as you type | |
IRB.conf[:USE_AUTOCOMPLETE] = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment