-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.sh
executable file
·72 lines (52 loc) · 1.62 KB
/
screenshot.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
66
67
68
69
70
71
72
#!/bin/zsh
# === Sparkler options ===
# Screenshot file type extension (png, jpg)
ext="png"
# URL for uploading
upload_url="https://mixtape.moe/upload.php"
# Folder to save screenshots to by default
save_folder="/home/henry/pictures/screenshots/"
# Name of multipart key to POST file as
file_key="files[]"
# Path of JSON response's URL / ID / whatever.
json_path=".files[0].url"
# Any prefix or suffix to append to the result extracted from JSON. You can leave these blank if your service responds with a full URL.
prelude=""
url_suffix=""
# === End of options ===
function notify {
notify-send -t 4000 -a sparkler "$1" "$2"
}
function upload {
local curl_response=$(curl -s -F "$file_key=@/tmp/shot.$ext" "$1")
if [[ $curl_response = '' ]]; then
notify "Image upload failed."
return 1
fi
local image_id=$(echo "$curl_response" | jq -r "$json_path")
echo -n "$prelude$image_id$url_suffix" | xsel -b
notify "Image uploaded" "$image_id"
}
function save {
local timestamp=$(date +%d%m%y-%H%M%S)
local filename="$save_folder/shot-$timestamp.$ext"
local result=$(zenity --file-selection --save --filename=$filename)
if [[ $result = '' ]]; then
notify "Image save cancelled."
return 1
fi
cp "/tmp/shot.$ext" "$result"
notify "Image saved" $(basename "$result")
}
maim -us "/tmp/shot.$ext"
if [[ $? = '1' ]]; then
notify "Image capture cancelled."
exit 1
fi
local choice=$(echo -e "upload\nsave" | dmenu -l 2 -p "action")
if [[ $choice = 'save' ]]; then
save
elif [[ $choice = 'upload' ]]; then
upload $upload_url
fi
rm "/tmp/shot.$ext"