screenshot.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. #TODO: check this https://askubuntu.com/questions/194427/what-is-the-terminal-command-to-take-a-screenshot
  4. display_help (){
  5. echo "Usage: ${0##*/} [m|u|s|c|1|4] {optional: 'upload'}"
  6. echo "Where first agruments must be:"
  7. echo -e "\t fullscreen | m --Takes screenshot of full screen"
  8. echo -e "\t focused | u \t--Takes screenshot of currently focused window"
  9. echo -e "\t selection | s \t--Lets you draw reclangle, saves screenshot"
  10. echo -e "\t clipboard | c \t--Lets you draw reclangle, takes screenshot to clipboard"
  11. echo -e "\t 16x9 | 1 \t--Takes screenshot of center, 16x9"
  12. echo -e "\t 4x3 | 4 \t--Takes screenshot of center, 4x3"
  13. echo ""
  14. echo -e "If your second argument will be 'upload', then screenshot will be uploaded and link saved to clipboard"
  15. echo -e "(it will overwrite screenshot in clipboard from -c flag if used)"
  16. exit 2
  17. }
  18. # # I have set this variable global, so I dont have to set it here
  19. # SCREENSHOTS="${HOME}/Documents/screenshots/"
  20. tmp="${SCREENSHOTS}/clipboard.png"
  21. name='%Y-%m-%d-%H%M%S_$wx$h.png'
  22. scrot_select="scrot -s -f -l style=dash,width=3,color=cyan"
  23. case $1 in
  24. fullscreen | full | m) scrot -m "$name" -e 'mv $f $$SCREENSHOTS' ;;
  25. focused | focus | u) scrot -u "$name" -e 'mv $f $$SCREENSHOTS' ;;
  26. 16x9 | 1) scrot -m -a 320,0,1920,1080 "$name" -e 'mv $f $$SCREENSHOTS' ;;
  27. 4x3 | 4) scrot -m -a 560,0,1440,1080 "$name" -e 'mv $f $$SCREENSHOTS' ;;
  28. selection | s) sleep 1; $scrot_select "$name" -e 'mv $f $$SCREENSHOTS' ;;
  29. clipboard | clip | c) sleep 1; $scrot_select -o "$tmp"; xclip -sel c -t image/png "$tmp" ;;
  30. *) display_help ;;
  31. esac
  32. # most recent file in screenshot directory
  33. recent="${SCREENSHOTS}/$(ls -At "$SCREENSHOTS" | head -n1)"
  34. notify-send -i "$recent" "$1 screenshot taken"
  35. [[ $2 == 'upload' ]] && upload.sh "$recent"
  36. # 4chan
  37. # Could be something to do with the filenames being the same and overwriting each other. Try this command instead, it makes the filenames different from one another
  38. # scrot '/tmp/%F_%T_$wx$h.png' -e 'xclip -selection clipboard -target image/png -i $f'
  39. # and for using the mouse to draw a rectangle to screenshot, just add the -s argument
  40. # scrot -s '/tmp/%F_%T_$wx$h.png' -e 'xclip -selection clipboard -ta