-
Notifications
You must be signed in to change notification settings - Fork 0
/
puush
103 lines (86 loc) · 2.3 KB
/
puush
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
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
# puush linux script
# By ThePengwin
# code for curl call taken from https://github.com/blha303/puush-linux
# Use how you wish!
#required programs
hash scrot 2>/dev/null || { echo >&2 "I require scrot but it's not installed. Aborting."; exit 1; }
hash notify-send 2>/dev/null || { echo >&2 "I require notify-send but it's not installed. Aborting."; exit 1; }
hash xclip 2>/dev/null || { echo >&2 "I require xclip but it's not installed. Aborting."; exit 1; }
#default opts
filetype="png"
scrotopts=""
# working out options
#
# -w current window
# -s selection of desktop
# -d desktop mode (f will be for a file)
# neither w or s = full screen
# -j Jpeg mode
# -p PNG mode
# neither = png mode
while getopts wsdpj opt; do
case $opt in
w)
scrotopts="-ub"
;;
s)
scrotopts="-s"
;;
d)
scrotopts=""
;;
p)
filetype="png"
;;
j)
filetype="jpg"
;;
esac
done
#things that dont change
tempdir="/tmp"
date=$(date '+%Y-%m-%d %H:%I:%S')
#puushkey stored in users dir in a file called .puushkey
puushkey=$(cat $HOME/.puushkey)
#file that scrot will make
file="$tempdir/Screenshot $date.$filetype"
#command to invoke scrot
cmd="scrot $scrotopts \"$file\""
#do it!
eval $cmd
scrotret=$?
#something fail?
if [ $scrotret -ne 0 ]; then
echo "Screenshot failed!"
exit 1
fi
#tell the user that we are going to upload
notify-send --icon=up "Puush" "Puushing \"$file\""
#upload and store results
puushvar=$(curl "https://puush.me/api/up" -F "k=$puushkey" -F "z=poop" -F "f=@$file" | sed -E 's/^.+,(.+),.+,.+$/\1\n/')
#and return code
pushret=$?
#no matter what, remove the file
rm "$file"
#curl failed hard, so warn user
if [ $pushret -ne 0 ]; then
notify-send --icon=up "Puush Failed!" "I dunno what happened, cURL went bad!"
exit 1
fi
#try and find errors puush sent us
case $puushvar in
"-1,")
notify-send --icon=up "Puush Failed!" "I think your API Key is broken :("
exit 1
;;
"-2,")
notify-send --icon=up "Puush Failed!" "I dunno what happened, but it didnt work!"
exit 1
;;
esac
#if we get here then we should be good!
#using xclip, add the url to the clipboard (-n for no newline)
echo -n "$puushvar" | xclip -selection clipboard
#and make a toast
notify-send --icon=up "Success!" "URL: $puushvar \n URL added to clipboard!"