-
Notifications
You must be signed in to change notification settings - Fork 0
/
pb.sh
executable file
·78 lines (65 loc) · 2.17 KB
/
pb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash -
#===============================================================================
#
# FILE: pb.sh
#
# USAGE: ./pb.sh -n vim.$$ -u -e 1W
#
# DESCRIPTION: Takes STDIN and outputs to Pastebin.com
#
# OPTIONS: -n <name> -u (unlisted) -e 1W (expires in 1 week)
# REQUIREMENTS: cURL, Pastebin PRO Subscription, OSX Keychain entries
# pastebin-api-[dev|user]-key.
# BUGS: ---
# NOTES: ---
# AUTHOR: Robert Sink (robert.sink@gmail.com)
# ORGANIZATION: ---
# CREATED: 12/12/2017 17:22
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
API_DEV_KEY=$(2>&1 security find-generic-password -ga pastebin-api-dev-key | grep "^password: " | cut -f2 -d\")
API_USER_KEY=$(2>&1 security find-generic-password -ga pastebin-api-user-key | grep "^password: " | cut -f2 -d\")
#########################################################################################
# default values
NAME="Robert Sink"
FORMAT=Bash
PRIVATE=1
EXPIRE_DATE=N
while getopts "n:f:e:hpu" OPTION
do
case $OPTION in
n)
NAME=$OPTARG
;;
f)
FORMAT="&api_paste_format=${OPTARG}"
;;
e)
EXPIRE_DATE=$OPTARG
;;
p)
PRIVATE=2
;;
u)
PRIVATE=1
;;
?)
echo "\
Pastebin.com Bash Script \
Usage : $0 [ -n <name> ] [ -f <format> ] [ -e <expiration> ] [ -p | -u ] [ -h ]
Input data using STDIN.
-n Specify the name of paste to be used
-f Specify code format used, use any of the values here http://pastebin.com/api#5
-e Specify expiration time, default never, examples here http://pastebin.com/api#6
-p Set paste private, requires a userkey, default public
-u Set paste unlisted, default public
"
exit
;;
esac
done
INPUT="$(</dev/stdin)"
querystring="api_option=paste&api_dev_key=${API_DEV_KEY}&api_user_key=${API_USER_KEY}&api_paste_expire_date=${EXPIRE_DATE}&api_paste_private=${PRIVATE}&api_paste_code=${INPUT}&api_paste_name=${NAME}${FORMAT}"
curl -s -d "${querystring}" http://pastebin.com/api/api_post.php
echo ""