bin/.local/bin/scrot_cmd (view raw)
1#!/bin/sh -e
2
3# a simple scrot wrapper to be used wm-agnostically
4
5usage() {
6 echo "usage: $0 [-n|--no-notify] [mode]"
7 echo
8 echo " -n, --no-notify do not show a notification on success"
9 echo
10 echo "modes:"
11 echo " -f, --full capture the whole screen"
12 echo " -a, --area select area and capture it"
13 echo " -c, --focused capture only focused window"
14 echo
15 echo "note: last specified mode will be chosen"
16}
17
18scrot_cmd() {
19 # scrot_cmd flags path
20
21 _scrot_exec="echo \$f >/dev/null"
22 [ "$_scrot_notify" = "YES" ] && {
23 _scrot_exec="notify-send -t $_scrot_notify_duration \"scrot\" \
24 \"screenshot of $_scrot_human_readable_mode is saved to \$f\""
25 }
26
27 # shellcheck disable=SC2086
28 scrot $1 "$2" -e "$_scrot_exec"
29}
30
31main() {
32
33 _scrot_dir="$HOME/Pictures/Screenshots"
34 _scrot_name="%Y-%m-%d-%s_\$wx\$h_scrot.png"
35 _scrot_path="$_scrot_dir/$_scrot_name"
36 _scrot_notify="YES"
37 _scrot_notify_duration="3000"
38 _scrot_flags=""
39 _scrot_human_readable_mode="full screen"
40
41 for arg in "$@"
42 do
43 case $arg in
44 -n|--no-notify)
45 _scrot_notify="NO"
46 ;;
47 -f|--full)
48 _scrot_flags=""
49 _scrot_human_readable_mode="full screen"
50 ;;
51 -a|--area)
52 _scrot_flags="-sf"
53 _scrot_human_readable_mode="screen area"
54 ;;
55 -c|--focused)
56 _scrot_flags="-u"
57 _scrot_human_readable_mode="active window"
58 ;;
59 *)
60 usage
61 exit 1
62 ;;
63 esac
64 done
65
66 scrot_cmd "$_scrot_flags" "$_scrot_path"
67
68}
69
70main "$@"