scripts

Various scripts for UNIX-like systems
git clone https://git.tronto.net/scripts
Download | Log | Files | Refs | README

dmenu-screenshot (759B)


      1 #!/bin/sh
      2 
      3 # Screenshot utility
      4 # Requires: dmenu (or similar), imagemagick
      5 
      6 # Usage: dmenu-screenshot [-m menu]
      7 
      8 usage() {
      9 	echo "Usage: dmenu-screenshot [-m MENU]"
     10 }
     11 
     12 menu="dmenu -i"
     13 prompt="Select type of screenshot:"
     14 
     15 while getopts "m:" opt; do
     16 	case "$opt" in
     17 		m)
     18 			menu="$OPTARG"
     19 			;;
     20 		*)
     21 			usage
     22 			exit 1
     23 			;;
     24 	esac
     25 done
     26 shift $((OPTIND - 1))
     27 
     28 folder="$HOME/pictures/screenshots"
     29 filename="screenshot_$(date +%Y-%m-%d-%H%M%S).png"
     30 filepath="${folder}/${filename}"
     31 
     32 t=$(printf 'Full\nSelection\n' | $menu -p "$prompt")
     33 if [ "$t" = "Full" ]; then
     34 	op="-window root"
     35 else
     36 	pkill xbanish # otherwise I can't use mouse to select area
     37 fi
     38 
     39 [ -n "$t" ] && sleep 0.1 && import $op "$filepath"
     40 spawn xbanish # This can be removed if you don't use xbanish