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.

108 lines
2.3 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 https://squiggle.city/~brennen/images/
  15. EXAMPLE:
  16. grab --select --public whatchamajig
  17. USE
  18. }
  19. simple_shot() {
  20. scrot "${_SCREEN_PATH:=$HOME/workspace/screenshots}/Screenshot-%Y-%m-%d-%T.png"
  21. printf "[\033[38;5;2mGOT IT\033[00m] ${_SCREEN_PATH:=$HOME/workspace/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/workspace/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/workspace/screenshots}" "$filename"
  42. else
  43. printf "[\033[38;5;2mGOT IT\033[00m] ${_SCREEN_PATH:=$HOME/workspace/screenshots}${filename}\n"
  44. fi
  45. }
  46. make_public() {
  47. if ! command -v scp > /dev/null 2>&1; then
  48. printf "[\033[5;38;5;1mERR\033[00m] scp 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. scp "${1}${2}" squiggle.city:~/public_html/images/
  54. printf "[\033[38;5;2mURL\033[00m] https://squiggle.city/~brennen/images${2}\n"
  55. }
  56. main () {
  57. if ! command -v scrot > /dev/null 2>&1; then
  58. printf "[\033[5;38;5;1mERR\033[00m] scrot command not found in $PATH\n"
  59. fi
  60. mkdir -p "${_SCREEN_PATH:=$HOME/workspace/screenshots}"
  61. if (( $# == 0 )); then
  62. simple_shot
  63. exit 0
  64. fi
  65. select=0
  66. public=0
  67. while [ -n "$1" ]; do
  68. case "$1" in
  69. --select|-s)
  70. select=1
  71. ;;
  72. --public|-p)
  73. public=1
  74. ;;
  75. --help|-h)
  76. show_help
  77. exit 0
  78. ;;
  79. *)
  80. path="$1"
  81. esac
  82. shift
  83. done
  84. take_shot
  85. }
  86. main "$@"