Created
August 21, 2011 05:36
-
-
Save ConradIrwin/1160187 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
| Pry.config.commands.command "edit-line", "Edits the current line in your editor" do | |
| require 'tempfile' unless defined? Tempfile | |
| to_edit = (eval_string =~ /^\s*$/ ? target.eval('inp[-1] || ""') : eval_string) | |
| temp_file = Tempfile.new('edit-line') | |
| temp_file.puts to_edit | |
| temp_file.close | |
| # HACK 1. this is a helper in the default command set. | |
| invoke_editor(temp_file.path, 0) | |
| eval_string.replace File.read(temp_file.path).sub(/\n*$/, "") | |
| temp_file.unlink | |
| unless eval_string =~ /^\s+$/ | |
| # HACK 2. Ensure the user can see the result of this eval by making | |
| # sure val is not empty... | |
| opts[:val].replace(" ") | |
| class << opts[:val]; def replace(*args); end; end | |
| run "show-input" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment