#!/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