When I answer questions here, I often want to see exactly what kind of errors the posted code is going to throw - so I copy it, open a file in 'vi', paste it in, and (following a careful look at it to make sure that it's not going to do anything nasty to me) run it. The additional bits - e.g., adding on a Perl shebang and running 'chmod +x' on the file - are already shortcuts in my 'vi', but I thought that it would be nice to automate this part, at least. I've got "pmedit" linked to an icon on my Gnome toolbar, so all I have to do now is select the code and click the icon. The displayed file will already contain the code that I highlighted.
The following is a Bourne shell script, and requires 'Xdialog'. Please feel free to modify for other OSes and situations. Constructive comments are highly welcomed. :)
#!/bin/sh
# Created by Ben Okopnik on Sun Apr 13 11:22:45 EDT 2008
cd /tmp
label="New filename:"
while :
do
fname=`Xdialog --stdout --inputbox "$label" 7 40`
# Weird: '-f' doesn't handle '~', so we'll do it by hand
fname=`echo $fname|sed 's/~/\/home\/ben/g'`
if [ -f "$fname" ]
then
label="\"$fname\" already exists. New name:"
else
[ "$fname" = "" ] && exit
xclip -o > "$fname"
xterm -e vi "$fname"
break
fi
done