commit c78adc92e2c3e8e5e89693079cfaa37db0789d3a
parent 94acad62776c665fb1c2219a33e08f437423e683
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Thu, 20 May 2021 23:42:53 -0400
Overhaul screenshot script to use dmenu
Diffstat:
1 file changed, 49 insertions(+), 21 deletions(-)
diff --git a/.local/bin/screenshot b/.local/bin/screenshot
@@ -1,29 +1,57 @@
#!/bin/sh
+# Simple POSIX shell script to take a screenshot using dmenu prompts
-filename="$HOME/media/pics/$(date "+%F-%H-%M-%S").png"
+# Get active monitors and format the geometry string in a way that maim can understand
+monitors=$(xrandr --listactivemonitors | awk '{print $4, $3}' | awk -F'[x/+* ]' '{print $1,$2"x"$4"+"$6"+"$7}')
-case $1 in
- "-d")
- maim -u > "$filename" \
+targets="Fullscreen
+Current Window
+Selected Region
+$(echo "$monitors" | awk '{print $1}')"
+
+destinations="File
+Clipboard
+Both"
+
+flags="-u"
+
+target=$(echo "$targets" | dmenu -i -l 20 -p 'Take screenshot of:' "$@") || exit 1
+saveto=$(echo "$destinations" | dmenu -i -l 20 -p 'Save to:' "$@" ) || exit 1
+
+filename="$HOME/media/pics/$(date +"%Y-%m-%d_%H-%M-%S").png"
+
+case "$target" in
+ "Fullscreen")
+ ;;
+ "Current Window")
+ flags="$flags -i $(xdotool getactivewindow)"
+ ;;
+ "Selected Region")
+ flags="$flags -s"
+ ;;
+ *)
+ geometry=$(echo "$target" | awk '{print $2}')
+ flags="$flags -g $geometry"
+ ;;
+esac
+
+case "$saveto" in
+ "File")
+ maim "$flags" > "$filename" \
&& notify-send -i camera-photo-symbolic "Screenshot Captured" \
- "Full desktop; saved to file."
- ;;
- "-w")
- maim -u -i $(xdotool getactivewindow) > "$filename" \
+ "Saved to $filename"
+ ;;
+ "Clipboard")
+ maim "$flags" | xclip -sel c -t image/png \
&& notify-send -i camera-photo-symbolic "Screenshot Captured" \
- "Current window only; saved to file."
- ;;
- "-s")
- maim -u -s > "$filename" \
+ "Copied to clipboard"
+ ;;
+ "Both")
+ maim "$flags" | tee "$filename" | xclip -sel c -t image/png \
&& notify-send -i camera-photo-symbolic "Screenshot Captured" \
- "Selected region; saved to file."
- ;;
+ "Saved to $filename and copied to clipboard"
+ ;;
*)
- echo "Invalid option, use -d, -w, or -s."
- ;;
+ exit 1
+ ;;
esac
-
-filesize="$(stat -c %s $filename)"
-if [ "$filesize" -eq 0 ]; then
- rm "$filename"
-fi