Last active
January 29, 2018 16:33
-
-
Save elgalu/5940941 to your computer and use it in GitHub Desktop.
IRB / Pry copy last result, a.k.a `_`, to your OSX / Linux / Windows clipboard using the 'clipboard' gem
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 'clipboard' #gem install clipboard | |
def cbcopy(value) | |
Clipboard.copy value unless value.empty? | |
flash_message = value.empty? ? "Sorry, nothing to copy" : "Copied to clipboard" | |
print "# #{flash_message}: " | |
puts %Q("#{value}") | |
end | |
# Copy last result to the Clipboard | |
def cp | |
cbcopy(IRB.CurrentContext.last_value.to_s) | |
end | |
# Copy last exception details to the Clipboard | |
def cpe | |
value = idk #TODO please help me fix this, $! doesn't work | |
cbcopy(value.nil? ? "" : value.inspect) | |
end |
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 'clipboard' #gem install clipboard | |
def cbcopy(value) | |
Clipboard.copy value unless value.empty? | |
flash_message = value.empty? ? "Sorry, nothing to copy" : "Copied to clipboard" | |
_pry_.output.print text.green("# #{flash_message}: ") | |
_pry_.output.puts %Q("#{value}") | |
end | |
Pry.commands.block_command("cp", "Copy last result to the Clipboard", :listing => "cp") do |line| | |
cbcopy(_pry_.last_result.to_s) | |
end | |
Pry.commands.block_command("cpe", "Copy last exception details to the Clipboard", :listing => "cpe") do |line| | |
value = _pry_.last_exception | |
cbcopy(value.nil? ? "" : value.inspect) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment