Skip to content

Instantly share code, notes, and snippets.

@LittleKey
Last active August 29, 2015 14:02
Show Gist options
  • Save LittleKey/65554abdaa567f8dc8da to your computer and use it in GitHub Desktop.
Save LittleKey/65554abdaa567f8dc8da to your computer and use it in GitHub Desktop.
pastebinit 简易封装....
#!/usr/bin/env ruby
#encoding: utf-8
lambda {
weblist = `pastebinit -l`.split("\n").map { |l| "http://" + $1 if /^\s*-\s*(.*?)\s*$/ =~ (l) }\
.delete_if { |l| l == nil }
author = 'LittleKey'
inputfile = []
syntax = 'python'
website = weblist.detect { |w| /.*debian.*/ =~ w }
Kernel.send :define_method, :Print_Weblist do
i = 0
weblist.each do |w|
puts "#{i += 1} - #{w}"
end
exit
end
Kernel.send :define_method, :Set_Input_File do |f|
inputfile << f.to_s
end
Kernel.send :define_method, :Set_Syntax do |s|
syntax = s.to_s
end
Kernel.send :define_method, :Set_Website do |w|
website = weblist[w - 1] if (1..weblist.length).include? w
end
Kernel.send :define_method, :Paste do
puts "Author: #{author} Syntax: #{syntax} Website: #{website}\n\n"
inputfile.each do |f|
puts `pastebinit -i '#{f}' -a '#{author}' -f '#{syntax}' -b '#{website}'`
end
end
}.call
def Kernel.method_missing(name, *args)
if /^-f(.*)$/ =~ name
Set_Syntax $1.downcase
elsif /^-b(\d*)$/ =~ name
Set_Website $1.to_i
elsif File.exists? name.to_s
Set_Input_File name
else
super(name, *args)
end
end
ARGV.each do |argument|
Kernel.send argument.to_sym
end
if ARGV.length == 0
puts 'Usage: LK_Paste [-fSyntax] [-bWebsiteNum] Inputfile [Inputfiles ...] [Print_Weblist]'
else
Kernel.send :Paste
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment