-
Notifications
You must be signed in to change notification settings - Fork 9
/
poomf
executable file
·144 lines (120 loc) · 3.2 KB
/
poomf
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
# poomf.sh
# Author: Joe Schillinger, William Woodruff
# ------------------------
# Upload to sr.ht and teknik.io.
# Heavily modified from Joe Schillinger's poomf.sh (now uguu.sh).
# ------------------------
# This code is licensed by Joe Schillinger under the MIT License.
# http://opensource.org/licenses/MIT
function usage() {
printf "%s <option>\n" $(basename ${0})
printf "%s\n" "Options:"
printf "%s\t\t\t%s\n" "-e" "don't strip exif data"
printf "%s\t\t\t%s\n" "-i" "interactive (zenity)"
printf "%s\t\t\t%s\n" "-f" "fullscreen screenshot"
printf "%s\t\t\t%s\n" "-h" "show this message"
printf "%s\t\t\t%s\n" "-s" "selection screenshot"
printf "%s\t\t%s\n" "-u <file>" "file upload"
exit
}
function info() {
notify-send ${@}
}
function installed() {
local cmd=$(command -v "${1}")
[[ -n "${cmd}" ]] && [[ -f "${cmd}" ]]
return ${?}
}
function check_dependencies() {
local deps=(notify-send zenity xclip curl jq exiftool)
for dep in "${deps[@]}"; do
if ! installed "${dep}" ; then
printf "Missing dependency '${dep}', please install it.\n"
exit 1
fi
done
}
function fullscreen_screenshot()
{
local cmd=
if installed maim ; then
cmd="maim ${1}"
elif installed gnome-screenshot ; then
cmd="gnome-screenshot -f ${1}"
elif installed scrot ; then
cmd="scrot ${1}"
else
info "Nothing to take a screenshot with."
exit 255
fi
eval "${cmd}"
}
function selection_screenshot()
{
local cmd=
if installed maim ; then
cmd="maim -s ${1}"
elif installed gnome-screenshot ; then
cmd="gnome-screenshot -a -f ${1}"
elif installed scrot ; then
cmd="scrot -s ${1}"
else
info "Nothing to take a screenshot with."
exit 255
fi
eval "${cmd}"
}
[[ -f ~/.api-keys/srht-api ]] && source ~/.api-keys/srht-api
check_dependencies
# get options
while getopts eifhsu: option; do
case "${option}" in
e) keepexif=1 ;;
i) interactive=1 ;;
f) fullscreen=1 ;;
h) usage ;;
s) selection=1 ;;
u) upload=1
file="${OPTARG}" ;;
*) exit ;;
esac
done
if [[ "${interactive}" ]]; then
file=$(zenity --file-selection)
fi
# take fullscreen picture
if [[ "${fullscreen}" ]]; then
file=$(filename=~/Dropbox/screenshots/$(date +%s).png ; fullscreen_screenshot "${filename}" ; printf "${filename}")
fi
# take selection picture
if [[ "${selection}" ]]; then
file=$(filename=~/Dropbox/screenshots/$(date +%s).png ; selection_screenshot "${filename}" ; printf "${filename}")
fi
if [[ -n "${file}" ]]; then
if [[ ! "${keepexif}" ]]; then
exiftool -overwrite_original -all= "${file}" > /dev/null
fi
if [[ -n "${SRHT_API_KEY}" ]]; then
output=$(curl -sf -F key="${SRHT_API_KEY}" -F file="@${file}" "https://sr.ht/api/upload")
if [[ -n "${output}" ]]; then
url=$(echo "${output}" | jq -M -r ".url")
success=1
fi
else
output=$(curl -sf -F file="@${file}" "https://api.teknik.io/upload/post")
if [[ -n ${output} ]]; then
url=$(echo "${output}" | jq -M -r ".[0].results.file.url")
success=1
fi
fi
fi
if [[ ${success} ]]; then
# copy link to clipboard
printf "${url}" | xclip -selection primary
printf "${url}" | xclip -selection clipboard
# notify user of completion
info "pomf!" "${url}"
else
info "%s\n" "file was not uploaded, did you specify a valid filename?"
fi