Skip to content

Instantly share code, notes, and snippets.

@ConradIrwin
Created July 25, 2011 00:26
Show Gist options
  • Save ConradIrwin/1103289 to your computer and use it in GitHub Desktop.
Save ConradIrwin/1103289 to your computer and use it in GitHub Desktop.
edit-line
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