mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
use jist for gisting
This commit is contained in:
parent
b92a589eab
commit
a79152c907
1 changed files with 35 additions and 17 deletions
|
@ -37,7 +37,7 @@ class Pry
|
||||||
end
|
end
|
||||||
alias_command "file-mode", "shell-mode"
|
alias_command "file-mode", "shell-mode"
|
||||||
|
|
||||||
create_command "gist", "Gist a method or expression history to github.", :requires_gem => "gist" do
|
create_command "gist", "Gist a method or expression history to github.", :requires_gem => "jist" do
|
||||||
|
|
||||||
include Pry::Helpers::DocumentationHelpers
|
include Pry::Helpers::DocumentationHelpers
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class Pry
|
||||||
attr_accessor :code_type
|
attr_accessor :code_type
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
require 'gist'
|
require 'jist'
|
||||||
self.content = ""
|
self.content = ""
|
||||||
self.code_type = :ruby
|
self.code_type = :ruby
|
||||||
end
|
end
|
||||||
|
@ -147,30 +147,25 @@ class Pry
|
||||||
|
|
||||||
# copy content to clipboard instead (only used with --clip flag)
|
# copy content to clipboard instead (only used with --clip flag)
|
||||||
def perform_clipboard
|
def perform_clipboard
|
||||||
Gist.copy(self.content)
|
copy(self.content)
|
||||||
output.puts "Copied content to clipboard!"
|
output.puts "Copied content to clipboard!"
|
||||||
end
|
end
|
||||||
|
|
||||||
def perform_gist
|
def perform_gist
|
||||||
type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
|
type_map = { :ruby => "rb", :c => "c", :plain => "plain" }
|
||||||
|
|
||||||
# prevent Gist from exiting the session on error
|
extname = opts.present?(:file) ? ".#{gist_file_extension(opts[:f])}" : ".#{type_map[self.code_type]}"
|
||||||
begin
|
|
||||||
extname = opts.present?(:file) ? ".#{gist_file_extension(opts[:f])}" : ".#{type_map[self.code_type]}"
|
|
||||||
|
|
||||||
if opts.present?(:lines)
|
if opts.present?(:lines)
|
||||||
self.content = restrict_to_lines(content, opts[:l])
|
self.content = restrict_to_lines(content, opts[:l])
|
||||||
end
|
|
||||||
|
|
||||||
link = Gist.write([:extension => extname,
|
|
||||||
:input => self.content],
|
|
||||||
!opts[:p])
|
|
||||||
rescue SystemExit
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if link
|
response = Jist.gist(self.content, :filename => extname,
|
||||||
Gist.copy(link)
|
:public => !!opts[:p])
|
||||||
output.puts "Gist created at #{link} and added to clipboard."
|
|
||||||
|
if response
|
||||||
|
copy(response['html_url'])
|
||||||
|
output.puts "Gist created at #{response['html_url']} and added to clipboard."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -197,6 +192,29 @@ class Pry
|
||||||
end
|
end
|
||||||
content
|
content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Copy a string to the clipboard.
|
||||||
|
#
|
||||||
|
# @param [String] content
|
||||||
|
#
|
||||||
|
# @copyright Copyright (c) 2008 Chris Wanstrath (MIT)
|
||||||
|
# @see https://github.com/defunkt/gist/blob/master/lib/gist.rb#L178
|
||||||
|
def copy(content)
|
||||||
|
cmd = case true
|
||||||
|
when system("type pbcopy > /dev/null 2>&1")
|
||||||
|
:pbcopy
|
||||||
|
when system("type xclip > /dev/null 2>&1")
|
||||||
|
:xclip
|
||||||
|
when system("type putclip > /dev/null 2>&1")
|
||||||
|
:putclip
|
||||||
|
end
|
||||||
|
|
||||||
|
if cmd
|
||||||
|
IO.popen(cmd.to_s, 'r+') { |clip| clip.print content }
|
||||||
|
end
|
||||||
|
|
||||||
|
content
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_command "clipit", "gist --clip"
|
alias_command "clipit", "gist --clip"
|
||||||
|
|
Loading…
Reference in a new issue