This repository was archived by the owner on Oct 31, 2023. It is now read-only.
forked from material-shell/material-awesome
-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathsnap
executable file
·120 lines (97 loc) · 2.64 KB
/
snap
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
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
# --- Simple screenshot script using maim and AwesomeWM API
# --
# -- Accepts `area` and `full` string args
# --
# -- For more details check `man maim`
# --
# -- @author manilarome <[email protected]>
# -- @copyright 2020 manilarome
# -- @script snap
# ----------------------------------------------------------------------------
screenshot_dir=$(xdg-user-dir PICTURES)/Screenshots/
# Check save directory
# Create it if it doesn't exist
function check_dir() {
if [ ! -d "$screenshot_dir" ];
then
mkdir -p "$screenshot_dir"
fi
}
# Main function
function shot() {
check_dir
file_loc="${screenshot_dir}$(date +%Y%m%d_%H%M%S).png"
maim_command="$1"
notif_message="$2"
# Execute maim command
${maim_command} "${file_loc}"
# Exit if the user cancels the screenshot
# So it means there's no new screenshot image file
if [ ! -f "${file_loc}" ];
then
exit;
fi
# Copy to clipboard
xclip -selection clipboard -t image/png -i "${screenshot_dir}"/`ls -1 -t "${screenshot_dir}" | head -1` &
awesome-client "
-- IMPORTANT NOTE: THIS PART OF THE SCRIPT IS LUA!
naughty = require('naughty')
awful = require('awful')
beautiful = require('beautiful')
dpi = beautiful.xresources.apply_dpi
local open_image = naughty.action {
name = 'Open',
icon_only = false,
}
local open_folder = naughty.action {
name = 'Open Folder',
icon_only = false,
}
local delete_image = naughty.action {
name = 'Delete',
icon_only = false,
}
-- Execute the callback when 'Open' is pressed
open_image:connect_signal('invoked', function()
awful.spawn('xdg-open ' .. '${file_loc}', false)
end)
open_folder:connect_signal('invoked', function()
awful.spawn('xdg-open ' .. '${screenshot_dir}', false)
end)
-- Execute the callback when 'Delete' is pressed
delete_image:connect_signal('invoked', function()
awful.spawn('gio trash ' .. '${file_loc}', false)
end)
-- Show notification
naughty.notification ({
app_name = 'Screenshot Tool',
icon = '${file_loc}',
timeout = 10,
title = '<b>Snap!</b>',
message = '${notif_message}',
actions = { open_image, open_folder, delete_image }
})
"
}
# Check the args passed
if [ -z "$1" ] || ([ "$1" != 'full' ] && [ "$1" != 'area' ]);
then
echo "
Requires an argument:
area - Area screenshot
full - Fullscreen screenshot
Example:
./snap area
./snap full
"
elif [ "$1" = 'full' ];
then
msg="Full screenshot saved and copied to clipboard!"
shot 'maim -u -m 1' "${msg}"
elif [ "$1" = 'area' ];
then
msg='Area screenshot saved and copied to clipboard!'
shot 'maim -u -s -n -m 1' "${msg}"
fi