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