From 20d778c95e7ea5f41e12f1b2f2d8d7a3c8de4abe Mon Sep 17 00:00:00 2001 From: zachir Date: Mon, 27 Feb 2023 01:08:44 -0600 Subject: add scrshot utility --- scrshot | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 scrshot (limited to 'scrshot') diff --git a/scrshot b/scrshot new file mode 100755 index 0000000..e270320 --- /dev/null +++ b/scrshot @@ -0,0 +1,50 @@ +#!/bin/sh + +output_text () { + notify-send "$1" "$2" + printf "$2\n" +} + +while getopts "hwxd:s:o:" o; do case "${o}" in + w) + DMENU="bemenu" + SCRSH="grim" + ;; + x) + DMENU="dmenu" + SCRSH="maim" + ;; + d) DARG="$OPTARG $DARG" ;; + s) SARG="$OPTARG $SARG" ;; + o) FILENAME="$OPTARG" ;; +esac done + +if [ -z "$DMENU" ]; then + if [ -n "$WAYLAND_DISPLAY" ]; then + DMENU="bemenu" + SCRSH="grim" + elif [ -n "$DISPLAY" ]; then + DMENU="dmenu" + SCRSH="maim" + else + output_text "Stuck" "Can't tell if Wayland or X, what gives?" + exit 1 + fi +fi + +TEMPNAME="$(mktemp -u | xargs basename)" +TEMPFILE="${TEMPNAME#tmp.}.png" + +"$SCRSH" $SARG "$TEMPFILE" + +if [ -z "$FILENAME" ]; then + FILENAME="$(echo "$TEMPFILE" | $DMENU $DARGS -p "What to name the file?")" + if [ -z "$FILENAME" ]; then + rm -rf "$TEMPFILE" + output_text "Deleted" "No filename selected, file deleted!" + exit + fi +fi + +mv "$TEMPFILE" "$FILENAME" + -- cgit v1.2.3