dotfiles/bin/screengrab

23 lines
374 B
Bash
Executable file

#!/usr/bin/env sh
set -euo pipefail
DIR=${XDG_SCREENSHOT_DIR:-$HOME}
TARGET="${DIR}/screenshot/grab-$(date +'%Y%m%d%H%M%S').png"
has() {
command -v $1 &>/dev/null
}
die() {
echo $1
exit 1;
}
has grim || die "missing grim"
has wl-copy || die "missing wl-copy"
has slurp || die "missing slurp"
grim -g "$(slurp)" $TARGET
if [ -s $TARGET ]; then
wl-copy < $TARGET
fi