-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoomf.sh
More file actions
executable file
·128 lines (108 loc) · 2.65 KB
/
poomf.sh
File metadata and controls
executable file
·128 lines (108 loc) · 2.65 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env bash
#
# poomf.sh - puush-like functionality for pomf.se and uguu.se
#
# by joe - js1 at openmailbox dot org
# refactored by arianon - arianon at openmailbox dot org
## CONFIGURATION
# Colors
N=$(tput sgr0)
R=$(tput setaf 1)
G=$(tput setaf 2)
# Screenshot utility
fscreen='maim --hidecursor'
sscreen='maim -s --hidecursor'
# Default screenshot name.
FILE='/tmp/screenshot.png'
## FUNCTIONS
function depends {
if ! command -v curl &> /dev/null; then
echo >&2 "Checking for curl... [${R}FAILED${N}]"
echo "\`curl\` not found."
exit 1
fi
}
function usage {
cat <<-HELP
poomf.sh - puush-like functionality for pomf.se and uguu.se
Usage:
$(basename "${0}") [options]
Options:
-h Show this help message.
-f Take a fullscreen screenshot.
-g Use uguu.se to upload.
It keeps files for one hour and has a 150MB max upload size.
-s Take a selection screenshot.
-t Use HTTPS, if the host supports it.
-u <file> Upload a file
HELP
}
## EXIT IF NO ARGUMENTS FOUND
if [[ -z "${1}" ]]; then
usage
exit 1
fi
depends
## PARSE OPTIONS
while getopts :fghstu: opt; do
case "${opt}" in
f)
# Take shot.
${fscreen} "${FILE}" ;;
g)
# Change mode to uguu
uguu=1 ;;
s)
# Take shot with selection.
${sscreen} "${FILE}" ;;
t)
# Use HTTPS
https=true ;;
u)
# Change $FILE to the specified file with -u
FILE="${OPTARG}" ;;
h)
# Show help and exit with EXIT_SUCCESS
usage && exit 0 ;;
*)
# Ditto, but with EXIT_FAILURE
usage && exit 1 ;;
esac
done
## UPLOAD FILE
for (( i = 1; i <= 3; i++ )); do
echo -n "Try #${i}... "
# Upload file to selected host
if [[ "${uguu}" ]]; then
if [[ "${https}" ]]; then
echo "[${R}FAILED${N}]"
echo "Uguu.se doesn't support HTTPS yet."
exit 1
else
pomf=$(curl -sf -F file="@${FILE}" "http://uguu.se/api.php?d=upload")
fi
else
if [[ "${https}" ]]; then
pomf=$(curl -sf -F files[]="@${FILE}" "https://pomf.se/upload.php?output=gyazo")
else
pomf=$(curl -sf -F files[]="@${FILE}" "http://pomf.se/upload.php?output=gyazo")
fi
fi
if (( "${?}" == 0 )); then
# Copy link to clipboard
echo -n "${pomf}" | xclip -selection primary
echo -n "${pomf}" | xclip -selection clipboard
# Log url to file
echo "$(date +"%D %R") | ${pomf}" >> ~/.pomfs.txt
# Notify user of completion
notify-send "pomf!" "${pomf}"
# Output message to term
echo "[${G}OK${N}]"
echo "File has been uploaded: ${pomf}"
exit
else
echo "[${R}FAILED${N}]"
fi
done
# If the program doesn't exit at the for-loop, the upload failed.
echo "File was not uploaded, did you specify a valid filename?"