Blame


1 432335a8 2022-02-21 op # sshot
2 432335a8 2022-02-21 op
3 432335a8 2022-02-21 op sshot is a simple script to make a screenshot!
4 432335a8 2022-02-21 op
5 432335a8 2022-02-21 op #!/bin/sh
6 432335a8 2022-02-21 op
7 432335a8 2022-02-21 op select=
8 062902d7 2022-02-21 op clip=
9 1ac9fd60 2022-02-21 op
10 1ac9fd60 2022-02-21 op Did you know that getopts is a built-in? The first version of this
11 1ac9fd60 2022-02-21 op script used getopt, but it was ugly and required some shell features
12 1ac9fd60 2022-02-21 op which I'm not sure are POSIX. getopts is easier to handle:
13 1ac9fd60 2022-02-21 op
14 062902d7 2022-02-21 op while getopts cs name; do
15 432335a8 2022-02-21 op case $name in
16 062902d7 2022-02-21 op c) clip=1 ;;
17 432335a8 2022-02-21 op s) select=1 ;;
18 d00ad61d 2022-10-03 op ?) echo "Usage: $0 [-cs]" >&2; exit 1 ;;
19 432335a8 2022-02-21 op esac
20 432335a8 2022-02-21 op done
21 432335a8 2022-02-21 op
22 062902d7 2022-02-21 op The usage is simple, it just accepts a -c flag to copy the image in the
23 062902d7 2022-02-21 op clipboard and a -s flag to select a window instead of grabbing the whole
24 062902d7 2022-02-21 op screen.
25 432335a8 2022-02-21 op
26 759cb1a6 2022-03-30 op The image is saved as /tmp/YYYYMMDDHHMMSS.png
27 432335a8 2022-02-21 op
28 432335a8 2022-02-21 op file=/tmp/`date +%Y%m%d%H%M%S`.png
29 432335a8 2022-02-21 op
30 432335a8 2022-02-21 op if [ -n "$select" ]; then
31 432335a8 2022-02-21 op maim -su > "$file"
32 432335a8 2022-02-21 op else
33 432335a8 2022-02-21 op maim -u > "$file"
34 432335a8 2022-02-21 op fi
35 432335a8 2022-02-21 op
36 432335a8 2022-02-21 op During the "select" maim aborts if a key is pressed; this however leaves
37 432335a8 2022-02-21 op a zero-byte file around, something I don't really like, so remove it in
38 432335a8 2022-02-21 op case
39 432335a8 2022-02-21 op
40 432335a8 2022-02-21 op if [ $? -ne 0 ]; then
41 432335a8 2022-02-21 op rm "$file"
42 432335a8 2022-02-21 op notify-send "sshot: aborted"
43 432335a8 2022-02-21 op exit 1
44 432335a8 2022-02-21 op fi
45 432335a8 2022-02-21 op
46 062902d7 2022-02-21 op Optionally save the image in the clipboard: (not the path, the whole
47 062902d7 2022-02-21 op image!)
48 062902d7 2022-02-21 op
49 062902d7 2022-02-21 op if [ -n "$clip" ]; then
50 062902d7 2022-02-21 op xclip -selection clipboard -t image/png -i "$file"
51 062902d7 2022-02-21 op fi
52 062902d7 2022-02-21 op
53 432335a8 2022-02-21 op Then send a notification to give a feedback of the success
54 432335a8 2022-02-21 op
55 432335a8 2022-02-21 op notify-send "sshot: done" "$file"