~smlavine/scripts

ref: 5af0022d2df522079823605c7340e26ab9847202 scripts/src/shoot -rwxr-xr-x 927 bytes
5af0022dSebastian LaVine dotfiles -> scripts 10 months ago
                                                                                
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
#!/bin/sh
# Copyright (c) 2019-2021 Sebastian LaVine <mail@smlavine.com>
# Licensed under the MIT license. See MIT.txt for details.
#
# File:        shoot
# Description: Saves a screenshot as PNG. Intended for use with a keybind.
# Options:     -d        Prompts for filename with dmenu instead of
#                        using timestamp.

picture_path="$HOME/Documents/pictures/screenshots/"

# take picture as soon as possible
file="$(mktemp)"
xwd -root | convert xwd:- png:"$file"

# read name from dmenu. Input from /dev/null so that it doesn't block for input
[ "$1" = "-d" ] && name=$(dmenu -p "Name?" < /dev/null) 

# either "-d" not used, OR dmenu cancelled out before input:
# generate name based on time taken
# example: "screenshot2019-11-17.948921698"
[ -z "$name" ] && name="screenshot$(date '+%F.%N')"

if [ -d "$picture_path" ]; then
	mv "$file" "$picture_path/$name.png"
else
	mv "$file" "$HOME/$name.png"
fi