-
Notifications
You must be signed in to change notification settings - Fork 5
/
dpaste
executable file
·91 lines (80 loc) · 1.78 KB
/
dpaste
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#+---------------------------------------+
#| dpaste |
#| author: Donald Merand |
#+---------------------------------------+
#| post a message to dpaste |
#+---------------------------------------+
HOST='http://dpaste.com/api/v1/'
TITLE="Post from CLI"
POSTER="TheCommandLine"
LANGUAGE="Bash"
HOLD=0
show_help() {
cat <<HELP
DPASTE SENDER
Usage - \`dpaste <options>\`
(or use a pipe eg: \`cat <file> | dpaste <options>\`
Options:
-h - Show this help screen
-o - "hold" the paste for 30 days
-t <title> - Specify title
-p <poster> - Specify poster
-l <lang> - Specify language
language can be Python, SQL, CSS, XML, Diff, Ruby, Apache, Bash, etc.
HELP
}
#test for existence of required programs
test_existence() {
program=$1
which ${program} &> /dev/null;
if [[ "$?" != "0" ]];
then
echo "'$program' appears to not be installed, check your PATH variable"
exit 1
fi
}
test_existence curl
while getopts ":hot:p:l:" OPTNAME
do
case "$OPTNAME" in
"h")
show_help
exit
;;
"o")
HOLD=1
;;
"t")
TITLE=$OPTARG
;;
"p")
POSTER=$OPTARG
;;
"l")
LANGUAGE=$OPTARG
;;
"?")
echo "Unknown option $OPTARG"
;;
":")
echo "No argument value for option $OPTARG"
;;
*)
# Should not occur
echo "Unknown error while processing options"
;;
esac
done
#now actually send the message
# vv silent, show headers in output
curl -si \
-F 'content=<-' \
-F "title=$TITLE" \
-F "language=$LANGUAGE" \
-F "poster=$POSTER" \
-F "hold=$HOLD" \
"$HOST" |
#filter out the location from the result
#got this code thanks to http://news.e-scribe.com/427
grep ^Location: | colrm 1 10