Pastebin It

Tony's Wiki | bash


I made a bash + curl script to paste code to http://www.pastebin.com

I saved it as ~/bin/pasteit

Useage is

   :~$ pasteit list

to list all of your pastes

or

   :~$ pasteit $filename

where $filename is the name of a file you wish to paste.

#!/bin/bash
 
# script to send text to pastebin.com
# first let's give it some relevant info
# your username, password, a title for your post, and what format (ie. what code language)
 
read -p "username:  " un
read -sp "password:  " pw
read -p "paste title: " pname
read -p "format (code type): " format
 
# now let's get a user session key
 
uk=$(curl -d api_dev_key="$yourAPIkey" -d api_user_name="$un" -d api_user_password="$pw" http://pastebin.com/api/api_login.php)
 
# now, either asking for the list,
# or sending the data to paste
 
if [[ $1 = "list" ]];
	then
		curl -d api_dev_key="$yourAPIkey" -d api_user_key="$uk" -d api_user_name="$un" -d api_user_password="$pw" -d api_option="list" http://pastebin.com/api/api_post.php
	else
		pc=$(cat $1)
	curl -d api_dev_key="$yourAPIkey" -d api_user_key="$uk" -d api_user_name="$un" -d api_user_password="$pw" -d api_option="paste" -d api_paste_code="$pc" -d api_paste_name="$pname" -d api_paste_format="$format" http://pastebin.com/api/api_post.php
fi

See the actual paste of this code to pastebin, done with this very script, here

I'm trying to figure out how to use this as a vim plugin. I found a vim plugin written in python that was supposed to do this, but it was written before recent changes to the pastebin.com api, so does not work. That was my motivation for trying to create my own plugin. Perhaps I should think about writing one in tcl, since that's my best language, to date…or just try to fix the existing python attempt to work with the new api, and learn some more python fu.

publicly editable talk/discussion page for this script


my pastebin

Now I have my own pastebin at http://tonybaldwin.me/paste/ using knoxious free pastebin. The API is different. I posted a script for pasting there at http://tonybaldwin.me/paste/index.php?7

#!/bin/bash
 
# © tony baldwin | tonybaldwin.me
# released according to the terms of the 
# Gnu General Public License v. 3
# http://www.gnu.org/copyleft/gpl.html
# send text to knoxious free pastebin
# for more info on api see
# https://pzt.me/formSample.html
 
if [[ $(echo $*) ]]; then
	file="$*"
else
	echo -e "What file, friend? \n "
	read file
fi
 
text=$(cat $file)
 
if [[ $(curl -d author=YOURNAME -d pasteEnter="$text" -d lifespan=0 -d highlighter=LANGUAGE http://YOURURL/api-adaptors/sharpshooter.php | egrep error) ]]; then
 
	echo ERROR
else
	echo SUCCESS
fi
exit 0

tonybaldwin June 18, 2011, at 11:08 PM


~~DISQUS~~