main dots / scripts / Scripts / ruby / paste.rb
xxwhirlpool  ·  2026-09-27
 1#!/usr/bin/env ruby
 2
 3require "tempfile"
 4
 5# provide file ext thru arg
 6# if not provided it's .txt
 7ext = ARGV[0] || "txt"
 8
 9# define tmpfile
10tmp = Tempfile.create(["pico-pastes-", ".#{ext}"])
11tmpfp = tmp.path
12
13# use $EDITOR, if empty use `nano`
14editor = ENV["EDITOR"] ||= "nano"
15
16# open tmpfile in editor
17system("#{editor} #{tmpfp}")
18
19# check if tmpfile exists or is empty
20# if one or the other, exit here
21if !File.exist?("#{tmpfp}") || File.empty?("#{tmpfp}")
22	puts "ERROR: #{tmpfp} does not exist or is empty"
23	exit 1
24end
25
26# send to pastes.sh
27cmd = "rsync #{tmpfp} pastes.sh:/"
28system(cmd)