simple-paste is a cli swiss army-knife for pasting, written in bash, powered by pb https://github.com/ptpb/pb
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.

simple-paste 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. # simple-paste
  3. # This file is part of simple paste -- cli based paste client
  4. #
  5. # Copyright 2017 Markus Meyer <coruja@siduction.org>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. # MA 02110-1301, USA.
  21. [ -f /etc/default/simple-paste.conf ] && source /etc/default/simple-paste.conf
  22. [ -f $HOME/.config/simple-paste.conf ] && source $HOME/.config/simple-paste.conf
  23. SP_COMMAND="upload"
  24. help () {
  25. echo "Usage: COMMAND | simple-paste [-e TIME]"
  26. echo " simple-paste -a|-s|-w [-e TIME]"
  27. echo " simple-paste [-e TIME] FILE"
  28. echo " simple-paste URL"
  29. echo " simple-paste -d UUID"
  30. echo "Options: -a paste screenshot of selected rectangle area (delay: 3s)"
  31. echo " -d UUID delete paste by its uuid"
  32. echo " -e TIME make paste be auto-deleted after TIME (default: 14 days)"
  33. echo " TIME must be Ns (seconds), Nm (minutes), Nh (hours),"
  34. echo " N or Nd (days), or Ny (years), e.g. 3h for 3 hours"
  35. echo " -s paste screenshot of whole screen (delay: 3s)"
  36. echo " -w paste screenshot of focused window (delay: 3s)"
  37. exit 0
  38. }
  39. seconds () {
  40. case ${1: -1} in
  41. s) s=${1:0:$(( ${#1} - 1 ))}
  42. ;;
  43. m) s=$(( ${1:0:$(( ${#1} - 1 ))} * 60 ))
  44. ;;
  45. h) s=$(( ${1:0:$(( ${#1} - 1 ))} * 3600 ))
  46. ;;
  47. d) s=$(( ${1:0:$(( ${#1} - 1 ))} * 86400 ))
  48. ;;
  49. y) s=$(( ${1:0:$(( ${#1} - 1 ))} * 31536000 ))
  50. ;;
  51. [0-9]) s=$(( $1 * 86400 ))
  52. ;;
  53. esac
  54. }
  55. check () {
  56. if [ $# -ne 1 ]
  57. then
  58. help
  59. else
  60. if [ -f $1 ]
  61. then
  62. SP_COMMAND="$SP_COMMAND $1"
  63. elif [[ $1 =~ ^http[s]?://.*$ ]]
  64. then
  65. SP_COMMAND="shorten_url $1"
  66. else
  67. help
  68. fi
  69. fi
  70. }
  71. upload () {
  72. curl $SP_UP_OPTIONS -F "c=@${1:--}" $SP_URL
  73. }
  74. delete () {
  75. curl -X DELETE $SP_URL$1
  76. }
  77. screenshot () {
  78. scrot -z -d 3 "$@" /tmp/$$.jpg
  79. upload /tmp/$$.jpg
  80. }
  81. shorten_url () {
  82. curl -F c=@- $SP_URL/u <<< $1
  83. }
  84. if [ $# -eq 0 ] && [ ! -p /dev/fd/0 ]
  85. then
  86. help
  87. fi
  88. while getopts "ad:e:sw" o
  89. do
  90. case $o in
  91. a) SP_COMMAND="screenshot -s"
  92. ;;
  93. d) SP_COMMAND="delete $OPTARG"
  94. ;;
  95. e) seconds $OPTARG
  96. SP_UP_OPTIONS="-F sunset=$s"
  97. ;;
  98. s) SP_COMMAND="screenshot"
  99. ;;
  100. w) SP_COMMAND="screenshot -u -b"
  101. ;;
  102. *) help
  103. ;;
  104. esac
  105. done
  106. shift $((OPTIND - 1))
  107. if [ $# -ne 0 ]
  108. then
  109. check "$@"
  110. fi
  111. $SP_COMMAND