summaryrefslogtreecommitdiff
path: root/.local/bin/screenshot
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/screenshot')
-rwxr-xr-x.local/bin/screenshot36
1 files changed, 36 insertions, 0 deletions
diff --git a/.local/bin/screenshot b/.local/bin/screenshot
new file mode 100755
index 0000000..419e70f
--- /dev/null
+++ b/.local/bin/screenshot
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+set -eu
+
+[ -f "$XDG_CONFIG_HOME/user-dirs.dirs" ] &&
+ . "$XDG_CONFIG_HOME/user-dirs.dirs"
+
+OUTPUT_PATH="${XDG_SCREENSHOTS_DIR:-${XDG_PICTURES_DIR:-$HOME}}/$(date +'%Y%m%d_%H%M%S').png"
+
+SELECT=0
+GEOM=
+
+while [ "$#" -ne 0 ]; do case "$1" in
+ -s | --select) SELECT=1; shift ;;
+ *) exit 1 ;;
+esac; done
+
+if [ "$SELECT" -eq 1 ]; then
+ GEOM=$(swaymsg -t get_tree | jq -r '.. | select(.pid? and .visible?) | .rect | "\(.x),\(.y) \(.width)x\(.height)"' | slurp -o)
+ [ -z "$GEOM" ] && exit 1
+fi
+
+set -- grim
+[ -n "$GEOM" ] && set -- "$@" -g "$GEOM"
+set -- "$@" "$OUTPUT_PATH"
+
+makoctl mode -a dnd >/dev/null
+"$@"
+makoctl mode -r dnd >/dev/null
+wl-copy -t image/png <"$OUTPUT_PATH"
+
+case "$(notify-send \
+ -A upload="Upload to image host" \
+ "screenshot" "Screenshot taken and saved to <b>${OUTPUT_PATH##*/}</b>.")" in
+*) ;;
+esac