From anonymous, 3 Months ago, written in Ruby.
This paste will bite the big one in 1 Second.
Embed
  1. #!/usr/bin/env ruby
  2. Signal.trap(:INT){ abort "\n(interrupted by SIGINT)" }
  3.  
  4. paste = ARGF.read
  5. $stdin = open "/dev/tty"
  6. puts "paste size: #{paste.size}"
  7. require_relative "../lib/paster"
  8. paster = Paster paste
  9.  
  10. require "tty-prompt"
  11. begin
  12.   TTY::Prompt.new.select "expiration:", {
  13.     "doesn't matter (1 hour)": [60, 3600],
  14.     "burn after reading": ["burn"],
  15.     "5 minutes": [5],
  16.     "1 hour": [60, 3600],
  17.     "1 day": [1440, 86400],
  18.     "3 days": [nil, 259200],
  19.     "1 week": [10080],
  20.     "1 month": [40320],
  21.     "3 months": [nil, 7776000],
  22.     "1 year": [483840],
  23.     "keep forever": [0, -1],
  24.   }.map{ |name, value|
  25.     paster = paster.dup
  26.     paster.expire = value
  27.     size = paster.services.size
  28.     size.zero? ?
  29.       {name: "#{name}", value: paster, disabled: "(no pastebins)"} :
  30.       {name: "#{name} (#{size})", value: paster}
  31.   }.tap{ |options|
  32.     abort "no pastebin for such size" if options.all?{ |_| _[:disabled] }   # TODO: better error message
  33.     # otherwise tty-prompt fails with an unhandled exception, lol
  34.   }, filter: true, cycle: true, per_page: 100
  35. rescue TTY::Reader::InputInterrupt
  36.   abort ""  # we don't use TTY::Prompt.new(interrupt: :exit) because it does not finish the line
  37. end.paste
  38.