-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprintSamuraiScreen
More file actions
executable file
·155 lines (139 loc) · 4.55 KB
/
printSamuraiScreen
File metadata and controls
executable file
·155 lines (139 loc) · 4.55 KB
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
#! /bin/bash
# System settings
screenshotsFolder=$(printf '%s' $HOME/Pictures/screenshots)
monitorResolution="1920x1080"
# Frame personalization
outsideFrameOpacity=00000070
colorFrame=aaff00
colorGrabber=467900
fontFamily="agave nerd font mono"
# Pidof programs
pidofsamurai=$(pgrep -f samurai-select)
pidofgrim=$(pgrep -f grim)
# Internal vars
silentPrint=false
# Get all variables right before starting printscreen
function AllNeededChecked() {
[[ ! $(type samurai-select) ]] && printf '%s' "samurai-select is not installed" && return 1
[[ ! $(type grim) ]] && printf '%s' "grim is not installed" && return 1
[[ ! $(type slurp) ]] && printf '%s' "slurp is not installed" && return 1
[[ ! $(type ksnip) ]] && printf '%s' "ksnip is not installed" && return 1
[[ $1 -eq 0 ]] && printf '%s' "No argument was declared" && return 1
[[ $1 -gt 1 ]] && printf '%s' "Too much arguments were declared" && return 1
if [[ ! -d $screenshotsFolder ]]; then
mkdir -p $screenshotsFolder
fi
}
# See and verify what argument was desired
function getScreenshot() {
case "$1" in
frame)
select-frame
;;
window)
select-window
;;
screen)
select-screen
;;
silent-screen)
silentPrint=true
select-screen
;;
geometry)
select-geometry
;;
*)
printf '%s' "No valid argument was declared"
exit 1
;;
esac
}
# Open printscreen when all verifications were successful with Ksnip
function getEdition() {
local lastScreenshot=$(ls -t $screenshotsFolder | head -n 1)
local pidofksnip=$(pgrep -f ksnip)
if [[ -n $pidofksnip ]] ; then
kill -15 $pidofksnip
fi
sleep 0.8
if $silentPrint ; then
$(hyprctl dispatch exec "[workspace 12 silent] ksnip -e $screenshotsFolder/$lastScreenshot") &> /dev/null &
else
ksnip -e $screenshotsFolder/$lastScreenshot &> /dev/null &
fi
exit 0
}
# A simplest frame selection for screenshot
function select-frame() {
if isSamuraiNotAlive ; then
runFramePrint && getEdition || exit 1
else
exit 1
fi
}
# A premade region selection for hyprland screenshot
function select-window () {
if isSamuraiNotAlive ; then
runWindowPrint && getEdition || exit 1
else
exit 1
fi
}
# A simple and fast screenshot using only grim, no previous frame edition
function select-screen() {
if isGrimNotAlive ; then
runGrimPrint && getEdition || exit 1
else
exit 1
fi
}
# A more robust selection with coordinates and customized frame for screenshot
function select-geometry() {
if isSamuraiNotAlive ; then
runGeometryPrint && getEdition || exit 1
else
exit 1
fi
}
# Verify if samurai's pid exists, otherwise exit
function isSamuraiNotAlive() {
[[ -z $pidofsamurai ]] && return 0 || return 1
}
# Verify if grim's pid exists, otherwise exit
function isGrimNotAlive() {
[[ -z $pidofgrim ]] && return 0 || return 1
}
# Verify output from samurai if screenshot was done
function samurai-verify() {
[[ $1 != "" ]] && return 0 || return 1
}
# Verify ouput from grim if screenshot was done
function grim-verify() {
[[ $1 == "" ]] && return 0 || return 1
}
# Do printscreen with the simplest selection frame
function runFramePrint() {
local print=$(samurai-select -s -z -A --no-anim --grabber-radius=6 --grabber-color=$colorGrabber --grabber-border-color=$colorGrabber --background-color=$outsideFrameOpacity --border-color=$colorFrame --border-width=3 -o "$screenshotsFolder"/%y-%M-%d_%h-%m-%s.png)
samurai-verify $print && return 0 || return 1
}
# Do printscreen with a calculated region for the active window
function runWindowPrint() {
local print=$(samurai-select -s -z -r hyprland --background-color=$outsideFrameOpacity --border-color=$colorFrame --border-width=4 -o "$screenshotsFolder"/%y-%M-%d_%h-%m-%s.png)
samurai-verify $print && return 0 || return 1
}
# Do printscreen with the robust frame selection (coordinates and customized frame)
function runGeometryPrint() {
local print=$(samurai-select -s -z -t -A --background-color=$outsideFrameOpacity --border-color=fffdbf --text-color=ffdf00 --grabber-color=fffdbf --grabber-border-color=255e0b --font-size=25 --font="$fontFamily" --border-width=3 --grabber-radius=6 -o "$screenshotsFolder"/%y-%M-%d_%h-%m-%s.png)
samurai-verify $print && return 0 || return 1
}
# Do printscreen with only Grim
function runGrimPrint() {
local print=$(grim -c -g "0,0 $monitorResolution" "$screenshotsFolder"/"$(date +%Y-%m-%d_%H-%M-%S)".png)
grim-verify $print && return 0 || return 1
}
# If all variables are ok, get the screenshot
if AllNeededChecked $# ; then
getScreenshot "$1"
fi
exit 1