diff options
author | tdback <tyler@tdback.net> | 2025-01-27 22:45:38 -0500 |
---|---|---|
committer | tdback <tyler@tdback.net> | 2025-01-27 22:45:38 -0500 |
commit | 303aa81d25df5f96ce980f2d38efb4a8ffc8faf7 (patch) | |
tree | 9bf4a0330986a6b37549b1da8fd5a7bd77fcfa94 /snapshot |
initial commit
Diffstat (limited to 'snapshot')
-rwxr-xr-x | snapshot | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/snapshot b/snapshot new file mode 100755 index 0000000..380051a --- /dev/null +++ b/snapshot @@ -0,0 +1,37 @@ +#!/bin/sh + +# snapshot: Take a screenshot using ImageMagick. Assumes `dunst` daemon is +# running when sending notifications. + +set -eu + +SCREENSHOT_DIR="$HOME/.local/screenshots" +SCREENSHOT_NAME="$SCREENSHOT_DIR/$(date '+%F_%R-%S' | sed 's/:/-/g').png" + +_end() { + dunstify "Screenshot captured:\n$SCREENSHOT_NAME" + display "$SCREENSHOT_NAME" + [ -t 1 ] && echo "$SCREENSHOT_NAME" + exit 0 +} + +region() { + import "$SCREENSHOT_NAME" + _end +} + +full() { + import -window root "$SCREENSHOT_NAME" + _end +} + +[ -d "$SCREENSHOT_DIR" ] || mkdir -p "$SCREENSHOT_DIR" + +[ "$#" -eq 0 ] && region + +while getopts ":f" arg; do + case "$arg" in + f) full ;; + *) printf "Invalid option: -%s\n" "$OPTARG" >&2 && exit 1 ;; + esac +done |