dotfiles/desktop/.local/bin/screenshot
Marty Oehme 2e0c992a54
wayland: Consolidate with mako into desktop module
Since the existing wayland module basically describes everything about
my 'desktop environment' setup already anyway, might as well rename it
accordingly. Additionally, mako is important for notifications in this
environment so it moves here as well.
2023-01-07 16:06:00 +01:00

48 lines
1 KiB
Bash
Executable file

#!/usr/bin/env sh
# Take a screenshot on wayland
# By default takes a screenshot of the whole desktop
# If 'region' or 'area' command is passed in will allow selecting a region to screenshot.
# Example: `screenshot region`
TIME="$(date +%Y-%m-%d-%H-%M-%S)"
readonly TIME
readonly TMPSCREENSHOTDIR="$HOME/.cache/screenshot"
readonly TMPIMGPATH="$TMPSCREENSHOTDIR/img-$TIME.png"
FULLSCREEN=true
if [ "$1" = "area" ] || [ "$1" = "region" ]; then
FULLSCREEN=false
fi
main() {
prepare_cache
take_screenshot "$FULLSCREEN"
if [ -n "$SCREENSHOT_POSTPROCESS" ]; then
eval "$SCREENSHOT_POSTPROCESS"
else
postprocess
fi
}
prepare_cache() {
if [ ! -d "$TMPSCREENSHOTDIR" ]; then
mkdir -p "$TMPSCREENSHOTDIR"
fi
}
take_screenshot() {
if $1; then
grim "$TMPIMGPATH"
else
grim -g "$(slurp)" "$TMPIMGPATH"
fi
}
postprocess() {
notify-send -i "$TMPIMGPATH" "Screenshot taken" "$TMPIMGPATH"
echo "$TMPIMGPATH" | wl-copy
echo "$TMPIMGPATH"
}
main "$@"