encrypt (781B)
1 #!/usr/bin/env ruby 2 3 require "open3" 4 5 file = ARGV.pop || raise("please supply a filename") 6 7 raise("file '#{file}' does not exist") unless File.exist?(file) 8 9 %x( 10 openssl \ 11 aes-256-cbc \ 12 -in #{file} \ 13 -out #{file}.enc \ 14 -pass file:secret.key \ 15 -iter 1000000 16 ) 17 18 caption_cmd = ["codex", "exec", "caption this image: #{file}"] 19 caption_output, status = Open3.capture2e(*caption_cmd) 20 21 unless status.success? 22 warn "Caption generation failed:\n#{caption_output}" 23 exit 1 24 end 25 26 caption = caption_output.split("\n").last.to_s.strip 27 28 if caption.empty? 29 warn "Caption output was empty." 30 exit 1 31 end 32 33 output = %[{{<dither #{ File.basename(file) } "782x600">}}#{ caption }{{</dither>}}] 34 35 IO.popen("pbcopy", "w") { |pb| pb.write(output) } 36 37 puts output 38 39 File.delete(file)