-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.sh
83 lines (73 loc) · 2.59 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
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env sh
# Restores the shader after screenshot has been taken
restore_shader() {
if [ -n "$shader" ]; then
hyprshade on "$shader"
fi
}
# Saves the current shader and turns it off
save_shader() {
shader=$(hyprshade current)
hyprshade off
trap restore_shader EXIT
}
save_shader # Saving the current shader
if [ -z "$XDG_PICTURES_DIR" ]; then
XDG_PICTURES_DIR="$HOME/Pictures"
fi
scrDir=$(dirname "$(realpath "$0")")
source $scrDir/globalcontrol.sh
swpy_dir="${confDir}/swappy"
save_dir="${2:-$XDG_PICTURES_DIR/Screenshots}"
save_file=$(date +'%y%m%d_%Hh%Mm%Ss_screenshot.png')
full_path="${save_dir}/${save_file}"
mkdir -p $save_dir
mkdir -p $swpy_dir
echo -e "[Default]\nsave_dir=$save_dir\nsave_filename_format=$save_file" >$swpy_dir/config
# Function to upload screenshot
upload_screenshot() {
local file="$1"
curl -H "authorization: {BEARER_TOKEN}" \
https://{HOSTNAME}/api/upload \
-F file=@"$file" \
-H "Content-Type: multipart/form-data" \
-H "Embed: true" | \
jq -r '.files[0]' | tr -d '\n' | wl-copy
}
function print_error
{
cat <<"EOF"
./screenshot.sh <action>
...valid actions are...
p : print all screens
s : snip current screen
sf : snip current screen (frozen)
m : print focused monitor
u : snip current screen (frozen) and upload
EOF
}
case $1 in
p) # print all outputs
grimblast copysave screen "$full_path" && restore_shader && swappy -f "$full_path" -o "$full_path" ;;
s) # drag to manually snip an area / click on a window to print it
grimblast copysave area "$full_path" && restore_shader && swappy -f "$full_path" -o "$full_path" ;;
sf) # frozen screen, drag to manually snip an area / click on a window to print it
grimblast --freeze copysave area "$full_path" && restore_shader && swappy -f "$full_path" -o "$full_path" ;;
m) # print focused monitor
grimblast copysave output "$full_path" && restore_shader && swappy -f "$full_path" -o "$full_path" ;;
u) # frozen screen, drag to manually snip an area / click on a window to print it, then upload
grimblast --freeze copysave area "$full_path" && restore_shader
if [ -f "$full_path" ]; then
upload_screenshot "$full_path"
notify-send -a "Screenshot" -i "$full_path" "Screenshot Uploaded"
else
notify-send -a "Screenshot" "Screenshot failed"
fi
;;
*) # invalid option
print_error ;;
esac
# For other options, we'll keep the existing behavior
if [ "$1" != "u" ] && [ -f "$full_path" ]; then
notify-send -a "Screenshot" -i "$full_path" "Saved in $save_dir"
fi