-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscreenshot.bash
executable file
·48 lines (40 loc) · 1.37 KB
/
screenshot.bash
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
#!/usr/bin/bash
#
# This script uses flameshot or maim to take a screenshot and
# upload it.
#
# Usage: ./screenshot.bash <option>
# option: gui: start flameshot gui
# full: capture all screens with flameshot (the whole resolution)
# screen: capture a specific screen (e.g. ./screenshot.bash screen -n 0)
# active: capture the currently active window with maim
# returns: 0 on success
# 1 on any error
title="Screenshot Uploader"
[[ "$1" != "gui" && "$1" != "full" && "$1" != "screen" && "$1" != "active" ]] && exit 1
cd "$(dirname "$0")" || exit 1
file="$(mktemp)"
if [[ "$1" != "active" ]]; then
if ! stderr="$(flameshot "$@" -r 2>&1 > "$file")"; then
notify-send -a "$title" "flameshot encountered an error!" "$stderr"
rm -f "$file"
exit 1
elif [[ "$stderr" == "flameshot: info: Screenshot aborted." ]]; then
rm -f "$file"
exit
fi
else
if ! maim -i "$(xdotool getactivewindow)" > "$file"; then
notify-send -a "$title" "maim/xdotool encountered an error!" "$(tr < "$file" -d '\000')"
rm -f "$file"
exit 1
fi
fi
if ! link="$("./screens-uploader.bash" "$file")"; then
notify-send -a "$title" "Upload failed!" "$link"
rm -f "$file"
exit 1
fi
rm -f "$file"
echo -n "$link" | xsel -ib
notify-send -a "$title" "Upload successful!" "The link has been copied to clipboard."