rofi-scrot.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. cmd="rofi"
  4. [[ $XDG_SESSION_TYPE=='wayland' ]] && cmd="wofi"
  5. DIR="${SCREENSHOTS:-${HOME}/Pictures}"
  6. [[ ! -d $DIR ]] && mkdir -p "$DIR"
  7. scrot_filename='%Y-%m-%d-%H%M%S_$wx$h.png'
  8. scrot_select="scrot -s -f -l style=dash,width=3,color=cyan"
  9. # options to be displayed
  10. option0="fullscreen"
  11. option1="focused"
  12. option2="selection"
  13. option3="clipboard"
  14. option4="16x9"
  15. option5="4x3"
  16. option6="selection-upload"
  17. options_all="${option0}\n${option1}\n${option2}\n${option3}\n${option4}\n${option5}\n${option6}"
  18. lines=$(echo -e "$options_all" | wc -l)
  19. selected="$(echo -e "$options_all" | $cmd -lines "$lines" -dmenu -p "scrot")"
  20. cd "$DIR"
  21. case $selected in
  22. $option0) scrot -m "$scrot_filename";;
  23. $option1) scrot -u "$scrot_filename";;
  24. $option2 | $option6) sleep 1; $scrot_select "$scrot_filename";;
  25. $option3) sleep 1; $scrot_select -o "$scrot_filename";;
  26. $option4) scrot -m -a 320,0,1920,1080 "$scrot_filename";;
  27. $option5) scrot -m -a 560,0,1440,1080 "$scrot_filename";;
  28. esac
  29. # most recent file in screenshot directory
  30. recent="$(find "$DIR" -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)"
  31. notify-send -i "$recent" "${selected} screenshot taken"
  32. case $selected in
  33. $option3) xclip -sel c -t image/png "$recent"; sleep 5m && rm "$recent";;
  34. $option6) upload.sh "$recent";;
  35. esac