-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot
executable file
·167 lines (127 loc) · 3.47 KB
/
screenshot
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use File::Basename;
use POSIX qw(strftime);
my $usage = <<'EOF';
Usage: screenshot [options...]
--select, -s
custom selection for screenshot
--wait, -s n
wait 'n' seconds before screenshot
--cursor, -c
show cursor in screenshot, default: off
--output, -o
choose which output to screenshot
--extra, -x
extra options to pass to grim/maim, in quotes
--no-notif, -n
do not send a notification when taking screenshot
--help, -h
show this usage information
EOF
my $display_server = '';
my $time_posix = strftime '%d-%m-%Y_%H-%M-%S', localtime;
my $pictures_dir = "$ENV{'HOME'}/Pictures";
my $screenshots_dir = "$pictures_dir/screenshots";
GetOptions(
'select|s' => \my $select,
'wait|w=i' => \my $wait_seconds,
'cursor|c' => \my $cursor,
'output|o=s' => \my $output,
'extra|x=s' => \my $extra_opts,
'no-nofif|n' => \my $no_notif,
'help|h' => \my $help
) or die "Invalid command line options given to $0, see --help for usage info";
if ($help)
{
print($usage);
exit 0;
}
if (! -d $screenshots_dir) {
print("\x1B[1;32mSCREENSHOT\x1B[0m: creating screenshots directory...\n");
mkdir($screenshots_dir);
}
my $grim = 'grim';
my $maim = 'maim';
my $file_name = "SCREEN_${time_posix}.png";
my $file_path = "${screenshots_dir}/${file_name}";
sub get_display_server
{
if ($ENV{"WAYLAND_DISPLAY"}) { $display_server = "wayland"; }
}
&get_display_server;
if ($display_server eq 'wayland') { &wayland } else { &x11 }
my $geometry = '';
sub x11
{
if ($select)
{
$geometry = &x_get_geometry;
print("\x1B[1;32mSCREENSHOT\x1B[0m: geometry selected -> ${geometry}\n");
}
if ($geometry) { $maim .= " -g '${geometry}'" }
if ($extra_opts) { $maim .= " ${extra_opts}" }
if ($cursor) { $maim .= " -u"; }
if ($wait_seconds)
{
print("\x1B[1;32mSCREENSHOT\x1B[0m: waiting \x1B[3m${wait_seconds}\x1B[0m seconds...\n");
&wait($wait_seconds);
}
print("\x1B[1;32mSCREENSHOT\x1B[0m: running \x1B[3m${maim} ${file_path}\x1B[0m\n");
system("$maim $file_path");
unless ($no_notif)
{
notif();
}
exit 0;
}
sub wayland
{
if ($select)
{
$geometry = &w_get_geometry;
print("\x1B[1;32mSCREENSHOT\x1B[0m: geometry selected -> ${geometry}\n");
}
if ($output) { $grim .= " -o ${output}" }
if ($geometry) { $grim .= " -g '${geometry}'" }
if ($extra_opts) { $grim .= " ${extra_opts}" }
if ($cursor) { $grim .= " -c"; }
if ($wait_seconds)
{
print("\x1B[1;32mSCREENSHOT\x1B[0m: waiting \x1B[3m${wait_seconds}\x1B[0m seconds...\n");
&wait($wait_seconds);
}
print("\x1B[1;32mSCREENSHOT\x1B[0m: running \x1B[3m${grim} ${file_path}\x1B[0m\n");
system("$grim $file_path");
unless ($no_notif)
{
notif();
}
system "wl-copy < ${file_path}";
exit 0;
}
sub wait
{
sleep($_[0]);
return;
}
sub x_get_geometry
{
my $geometry = `slop`;
chomp($geometry);
return $geometry;
}
sub w_get_geometry
{
my $geometry = `slurp -d -b '#00000050' -c '#6AA1FD'`;
chomp($geometry);
return $geometry;
}
sub notif
{
my $picture_name = basename($file_path);
system("notify-send --category=screenshot --icon=${file_path} 'Screenshot taken' '${picture_name}'");
return;
}