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. :)
# Created by Ben Okopnik on Sun Apr 13 11:22:45 EDT 2008
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" ]
label="\"$fname\" already exists. New name:"
[ "$fname" = "" ] && exit
xclip -o > "$fname"
xterm -e vi "$fname"
Playing with code found on Perlmonks
Download Code Replies are listed 'Best First'.
I'm surprised Xdialog doesn't have a specific direct filename mode.
I installed it to try it out, and (for me, anyway) it dragged in gtk 1.2
libraries, so I poked around for a gtk 2.0 equivalent and found zenity,
which has handy "--file-selection --save" options.
That's really odd - I thought (based on what it looks like) that 'Xdialog' was one of the old guard; the Athena Toolkit or something like that. Bleh. :(
On the other hand, modifying it to use none of those libraries, at least for the dialog end, is trivial: change 'Xdialog' to 'dialog', remove the 'xterm -e' line from the 'vi' invocation, and launch the whole script as 'xterm -e pmedit'.
Human history becomes more and more a race between education and catastrophe. -- HG Wells