From a3a7cf765ea98805b3370b23a84c48337c02c78a Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 3 Nov 2020 13:06:33 +0100 Subject: [PATCH] chore: add upload function --- zshrc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/zshrc b/zshrc index 5772c8e..251ee06 100644 --- a/zshrc +++ b/zshrc @@ -214,3 +214,22 @@ transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi;tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; } info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; } + upload() { + # inspired by https://www.alexander-pluhar.de/paste-file-host.html + # make eternity the default lifespan + FILE_LIFESPAN=${2:-e} + FILE_ID=$(base64 /dev/urandom | tr -d '/+' | dd bs=16 count=1 2>/dev/null) + + rsync $1 nebula:/var/www/htdocs/dotya.ml/files/$FILE_LIFESPAN/$FILE_ID-$1 + + FILE_URL="https://dotya.ml/files/$FILE_LIFESPAN/$FILE_ID-$1" + + if [[ -z "$WAYLAND_DISPLAY" ]]; then + echo $FILE_URL | xclip -selection clipboard + echo $FILE_URL | xsel --clipboard --input + else + echo $FILE_URL | wl-copy + fi + + echo $FILE_URL + }