Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.2 KiB

  1. #!/usr/bin/env bash
  2. # forked from Tyler at:
  3. # https://github.com/thcipriani/dotfiles
  4. # https://github.com/thcipriani/dotfiles/commit/1c39af38fafaf24a22474930d18d77edb8931611
  5. #
  6. # TODO:
  7. # [ ] uploads
  8. show_help() {
  9. cat<<USE
  10. USAGE:
  11. grab [screenshotname]
  12. OPTIONS:
  13. --select|-s: use selection rectangle
  14. --public|-p: upload it to http://tyler.zone
  15. EXAMPLE:
  16. grab --select --public whatchamajig
  17. USE
  18. }
  19. simple_shot() {
  20. \scrot "${_SCREEN_PATH:=$HOME/screenshots}/Screenshot-%Y-%m-%d-%T.png"
  21. printf "[\033[38;5;2mGOT IT\033[00m] ${_SCREEN_PATH:=$HOME/screenshots}/Screenshot-$(date +%Y-%m-%d-%T).png\n"
  22. }
  23. take_shot() {
  24. default_path="Screenshot-%Y-%m-%d-%T"
  25. if (( $(printf "$path" | wc -c) < 1 )); then
  26. path="$default_path"
  27. grabname=1
  28. else
  29. filename="/${path}.png"
  30. fi
  31. options=''
  32. if (( select == 1 )); then
  33. options="-s"
  34. printf "[\033[38;5;2mSELECT\033[00m] Waiting for your selection\n"
  35. fi
  36. \scrot ${options} "${_SCREEN_PATH:=$HOME/screenshots}/${path}.png"
  37. if (( grabname == 1 )); then
  38. filename="/Screenshot-$(date +%Y-%m-%d-%T).png"
  39. fi
  40. if (( $public == 1 )); then
  41. make_public "${_SCREEN_PATH:=$HOME/screenshots}" "$filename"
  42. else
  43. printf "[\033[38;5;2mGOT IT\033[00m] ${_SCREEN_PATH:=$HOME/screenshots}${filename}\n"
  44. fi
  45. }
  46. make_public() {
  47. if ! command -v s3cmd > /dev/null 2>&1; then
  48. printf "[\033[5;38;5;1mERR\033[00m] s3cmd command not found in $PATH\n"
  49. fi
  50. if (( $# < 2 )); then
  51. printf "[\033[5;38;5;1mERR\033[00m] need a path and a folder\n"
  52. fi
  53. \s3cmd put "${1}${2}" s3://tyler.zone
  54. \s3cmd setacl --acl-public "s3://tyler.zone${2}"
  55. printf "[\033[38;5;2mURL\033[00m] http://tyler.zone${2}\n"
  56. }
  57. main () {
  58. if ! command -v scrot > /dev/null 2>&1; then
  59. printf "[\033[5;38;5;1mERR\033[00m] scrot command not found in $PATH\n"
  60. fi
  61. mkdir -p "${_SCREEN_PATH:=$HOME/screenshots}"
  62. if (( $# == 0 )); then
  63. simple_shot
  64. exit 0
  65. fi
  66. select=0
  67. public=0
  68. while [ -n "$1" ]; do
  69. case "$1" in
  70. --select|-s)
  71. select=1
  72. ;;
  73. --public|-p)
  74. public=1
  75. ;;
  76. --help|-h)
  77. show_help
  78. exit 0
  79. ;;
  80. *)
  81. path="$1"
  82. esac
  83. shift
  84. done
  85. take_shot
  86. }
  87. main "$@"