123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- #!/bin/bash
-
- # simple-paste
- # This file is part of simple paste -- cli based paste client
- #
- # Copyright 2017 Markus Meyer <coruja@siduction.org>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
-
- [ -f /etc/default/simple-paste.conf ] && source /etc/default/simple-paste.conf
- [ -f $HOME/.config/simple-paste.conf ] && source $HOME/.config/simple-paste.conf
-
- SP_COMMAND="upload"
-
- help () {
- echo "Usage: COMMAND | simple-paste [-e TIME]"
- echo " simple-paste -a|-s|-w [-e TIME]"
- echo " simple-paste [-e TIME] FILE"
- echo " simple-paste URL"
- echo " simple-paste -d UUID"
- echo "Options: -a paste screenshot of selected rectangle area (delay: 3s)"
- echo " -d UUID delete paste by its uuid"
- echo " -e TIME make paste be auto-deleted after TIME (default: 14 days)"
- echo " TIME must be Ns (seconds), Nm (minutes), Nh (hours),"
- echo " N or Nd (days), or Ny (years), e.g. 3h for 3 hours"
- echo " -s paste screenshot of whole screen (delay: 3s)"
- echo " -w paste screenshot of focused window (delay: 3s)"
- exit 0
- }
-
- seconds () {
- case ${1: -1} in
- s) s=${1:0:$(( ${#1} - 1 ))}
- ;;
- m) s=$(( ${1:0:$(( ${#1} - 1 ))} * 60 ))
- ;;
- h) s=$(( ${1:0:$(( ${#1} - 1 ))} * 3600 ))
- ;;
- d) s=$(( ${1:0:$(( ${#1} - 1 ))} * 86400 ))
- ;;
- y) s=$(( ${1:0:$(( ${#1} - 1 ))} * 31536000 ))
- ;;
- [0-9]) s=$(( $1 * 86400 ))
- ;;
- esac
- }
-
- check () {
- if [ $# -ne 1 ]
- then
- help
- else
- if [ -f $1 ]
- then
- SP_COMMAND="$SP_COMMAND $1"
- elif [[ $1 =~ ^http[s]?://.*$ ]]
- then
- SP_COMMAND="shorten_url $1"
- else
- help
- fi
- fi
- }
-
- upload () {
- curl $SP_UP_OPTIONS -F "c=@${1:--}" $SP_URL
- }
-
- delete () {
- curl -X DELETE $SP_URL$1
- }
-
- screenshot () {
- scrot -z -d 3 "$@" /tmp/$$.jpg
- upload /tmp/$$.jpg
- }
-
- shorten_url () {
- curl -F c=@- $SP_URL/u <<< $1
- }
-
- if [ $# -eq 0 ] && [ ! -p /dev/fd/0 ]
- then
- help
- fi
-
- while getopts "ad:e:sw" o
- do
- case $o in
- a) SP_COMMAND="screenshot -s"
- ;;
- d) SP_COMMAND="delete $OPTARG"
- ;;
- e) seconds $OPTARG
- SP_UP_OPTIONS="-F sunset=$s"
- ;;
- s) SP_COMMAND="screenshot"
- ;;
- w) SP_COMMAND="screenshot -u -b"
- ;;
- *) help
- ;;
- esac
- done
- shift $((OPTIND - 1))
-
- if [ $# -ne 0 ]
- then
- check "$@"
- fi
-
- $SP_COMMAND
|