diff --git a/functions.sh b/functions.sh index f044a11..70e6ed6 100755 --- a/functions.sh +++ b/functions.sh @@ -115,17 +115,34 @@ function httpserver } alias webserver='httpserver' -## Upload something using the transfer.sh service. Usage: transfer filename -function transfer +## Upload something using the 0x0.st service. Usage: upload [filename|url] +function upload { - basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g') - out=$(curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile") + local url + if echo "$@" | grep -E -s -q "^http[s]://"; then + url=true + fi + if [[ $url == true ]]; then + out="$(curl -F"url=$@" https://0x0.st)" + else + out=$(curl --progress-bar -F"file=@$@" "https://0x0.st/") + fi + if [[ $? -ne 0 ]]; then + echo -e "Failed uploading $@:\n $out" >&2 + return + fi + echo -e "Done, file at:\t$out" if [[ $(uname) == "Darwin" ]]; then - echo "$out" | pbcopy + clipboard="pbcopy" + elif command -v wl-copy; then + clipboard="wl-copy" + elif command -v xclip; then + clipboard="xclip" else - echo "$out" + clipboard="cat" fi + echo -n"$out" | $clipboard } ## If connecting through ssh and reverse forwarding port 2222 (ssh -R 2222:localhost:22 ), this function allows to copy the files back to the machine one is connecting from by typing 'mecp filename' (configure the username for "localhost" in ~/.ssh/config or add an username)