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.

mbin.sh 1.0KB

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. # Set MKR_BIN if not set. Export it in your shell rc to use a self hosted
  3. # instance. Include the trailing slash with custom urls.
  4. MKR_BIN=${MKR_BIN:-https://bin.mkr.pw/}
  5. HASTEBIN=${HASTEBIN:0}
  6. EDITOR=${EDITOR:-vim}
  7. if [[ $1 == "-c" || $1 == "--clipboard" ]]; then
  8. text=$(xclip -selection clipboard -out)
  9. op=$(curl -s --data-binary "${text}" -H "Content-Type:text/plain" $MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents))
  10. elif [ -t 0 ]; then
  11. tmp_file=$(mktemp)
  12. $EDITOR $tmp_file
  13. op=$(curl -s --data-binary "@${tmp_file}" -H "Content-Type:text/plain" $MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents))
  14. rm $tmp_file
  15. else
  16. op=$(curl -s --data-binary "@-" -H "Content-Type:text/plain" $MKR_BIN$([[ $HASTEBIN == 1 ]] && echo documents))
  17. fi
  18. if [[ $HASTEBIN == 1 ]]; then
  19. link=$(echo $op | jq -r .key)
  20. else
  21. link=$(echo $op | cut -f2 -d'/')
  22. fi
  23. if [[ -v DISPLAY ]]; then
  24. echo ${MKR_BIN}${link} | tee /dev/tty | xclip -selection clipboard
  25. xdg-open ${MKR_BIN}${link}
  26. else
  27. echo ${MKR_BIN}${link}
  28. fi