mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-21 19:11:30 +01:00
functions: replace transfer() with upload()
transfer.sh is no longer around, replace it with 0x0.st
This commit is contained in:
parent
95e74f1d32
commit
a6997cc37c
29
functions.sh
29
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user