Tools to interface with Teknik Services.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

teknik.sh 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/bash
  2. #
  3. # teknik - Upload files/scrots/urls to teknik.io (rip pomf & uguu ;_;7)
  4. # This script requires maim / xclip / wget be installed.
  5. # By onodera, modified by SirCmpwn
  6. # Further modified by alusion
  7. ## CONFIGURATION
  8. # Copy links to clipboard after upload (requires xclip)
  9. clipboard=true
  10. # Send a notification when done
  11. notify=true
  12. # Open URL in browser
  13. browser=false
  14. # Log URLs
  15. log=false
  16. # Log file location
  17. logfile="$HOME/.teknik"
  18. ## FUNCTIONS
  19. bin_there() {
  20. if ! type "$@" >/dev/null 2>&1 ; then
  21. echo "$@ not installed."
  22. exit 1
  23. fi
  24. }
  25. # This function sets $file to a selection scrot
  26. selection() {
  27. bin_there "maim"
  28. uploadme="/tmp/scrot.png"
  29. maim --hidecursor -s -b 3 -c 250,250,250 "$uploadme" 2> "/dev/null"
  30. if [[ "$?" -ge 1 ]]; then
  31. echo "Selection cancelled.">&2
  32. exit 1
  33. fi
  34. word=selection
  35. }
  36. # This function sets $file to your clipboard contents
  37. clipboard() {
  38. bin_there "xclip"
  39. uploadme="/tmp/scrot.txt"
  40. xclip -o > "$uploadme"
  41. word=clipboard
  42. }
  43. # This function sets $file an url
  44. url() {
  45. bin_there "wget"
  46. type="$(echo "$location" | rev | cut -d "." -f 1 | rev)"
  47. uploadme="/tmp/url.$type"
  48. wget --quiet "$location" -O "$uploadme"
  49. word=url
  50. }
  51. # This function sets $file a file
  52. file() {
  53. if [[ -f "$location" ]]; then
  54. uploadme="$location"
  55. else
  56. echo "File not found.">&2
  57. exit 1
  58. fi
  59. word=file
  60. }
  61. # This function sets $file to a full screen scrot
  62. desktop() {
  63. bin_there "maim"
  64. uploadme="/tmp/scrot.png"
  65. maim --hidecursor "$uploadme"
  66. word=desktop
  67. }
  68. # This function uploads the $file
  69. upload() {
  70. url=$(curl --silent -F file="@$uploadme" "https://api.teknik.io/v1/Upload")
  71. if [[ "${url}" =~ "error" ]]; then
  72. printf 'error uploading file!\n'
  73. exit 1
  74. else
  75. url="${url##*fileName\":\"}"
  76. url="https://u.teknik.io/${url%%\"*}"
  77. fi
  78. }
  79. # This function logs the url, copies the url to the clipboard, and/or opens the url in your browser
  80. feedback() {
  81. # Copy url to clipboard
  82. if [[ "$clipboard" == true ]]; then
  83. bin_there "xclip"
  84. echo "$url" | xclip -selection primary
  85. echo "$url" | xclip -selection clipboard
  86. fi
  87. # Log url
  88. if [[ "$log" == true ]]; then
  89. echo "$url" >> "$logfile"
  90. fi
  91. # Open url in browser
  92. if [[ "$browser" == true ]]; then
  93. xdg-open "$url"
  94. fi
  95. # Send notification
  96. if [[ "$notify" == true ]]; then
  97. notify-send "Upload complete: $url"
  98. fi
  99. echo "${url}"
  100. }
  101. ## EXECUTE
  102. if [[ "$#" -ge 1 ]]; then
  103. case "$@" in
  104. -h|--help)
  105. echo "usage: teknik [options] [file/url]"
  106. echo "options:"
  107. echo " -h, --help print help and exit"
  108. echo " -p, --paste upload your clipboard as text"
  109. echo " -s, --selection upload selection scrot"
  110. echo " -v, --version print version and exit"
  111. exit 0
  112. ;;
  113. -s|--selection)
  114. selection
  115. ;;
  116. -v|--version)
  117. echo "teknik 0.1.1"
  118. exit 0
  119. ;;
  120. -p|--paste)
  121. clipboard
  122. ;;
  123. http*)
  124. location="$@"
  125. url
  126. ;;
  127. *)
  128. location="$@"
  129. file
  130. ;;
  131. esac
  132. else
  133. desktop
  134. fi
  135. if [[ "$#" -eq 0 ]]; then
  136. desktop
  137. fi
  138. upload
  139. feedback