Skip to content

Instantly share code, notes, and snippets.

@matheuseduardo
Last active January 15, 2024 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matheuseduardo/00a81c7cae5677d6f4ef7e48807fc1f7 to your computer and use it in GitHub Desktop.
Save matheuseduardo/00a81c7cae5677d6f4ef7e48807fc1f7 to your computer and use it in GitHub Desktop.
script to use transfer.sh website
keep() {
# check arguments
if [ $# -ne 1 ];
then
echo -e "Wrong arguments specified. Usage:\nkeep /tmp/test.md\ncat /tmp/test.md | keep test.md"
return 1
fi
# get temporary filename, output is written to this file so show progress can be showed
tmpfile="$( mktemp -t keepXXX )"
# upload stdin or file
file="$1"
if tty -s;
then
basefile="$( basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g' )"
if [ ! -e $file ];
then
echo "File $file doesn't exists."
return 1
fi
if [ -d $file ];
then
# zip directory and transfer
zipfile="$( mktemp -t keepXXX.zip )"
cd "$(dirname "$file")" && zip -r -q - "$(basename "$file")" >> "$zipfile"
curl --progress-bar --insecure --upload-file "$zipfile" "https://free.keep.sh/$basefile.zip" >> "$tmpfile"
rm -f $zipfile
else
# transfer file
curl --progress-bar --insecure --upload-file "$file" "https://free.keep.sh/$basefile" >> "$tmpfile"
fi
else
# transfer pipe
curl --progress-bar --insecure --upload-file "-" "https://free.keep.sh/$file" >> "$tmpfile"
fi
# cat output link
cat "$tmpfile"
# copy to clipboard
cat "$tmpfile" > /dev/clipboard
echo
# cleanup
rm -f "$tmpfile"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment