forked from acieroid/paste-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paste.sh
executable file
·65 lines (48 loc) · 1.22 KB
/
paste.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
#!/bin/sh
usage="Usage: $0 [-s] [-l language] [-u user] [-c] [ -C copy_command ] [ -p pastebin_url ] file\n
-s: toggles silent mode (do not print the final URL)\n
-c: copies the final URL to clipboard"
if [ "$#" -lt 1 ] ; then
echo -e $usage;
exit
fi
pastebin_url="http://paste.awesom.eu"
user=""
copy=""
lang=""
print="yes"
which xclip > /dev/null
if [ "$?" -eq 0 ] ; then
copy_cmd="$(which xclip) -i"
else
which xsel > /dev/null
if [ "$?" -eq 0 ] ; then
copy_cmd="$(which xsel)"
fi
fi
while getopts :l:u:csC:p: option
do
case "$option" in
l) language="$OPTARG";;
u) user="$OPTARG";;
c) copy="yes";;
s) print="";;
C) copy_command="$OPTARG";;
p) pastebin_url="$OPTARG";;
?) echo -e $usage;
exit;;
esac
done
shift $(($OPTIND - 1))
file=$1
if [ ! "$language" ] ; then
ext="$(echo \"$file\"|sed -e 's/.*\.//')"
fi
paste=$(curl -d "hl=${language}&ext=${ext}&user=${user}&escape=on&script" --data-urlencode "paste@${file}" "$pastebin_url" 2>/dev/null)
final="$pastebin_url/$paste"
if [ "$print" = "yes" ] ; then
echo "$final"
fi
if [ "$copy" = "yes" -a -n "$copy_command" ] ; then
echo "$final" | $copy_command
fi