Add function/alias to allow uploading files to http://transfer.sh from the commandline.
This commit is contained in:
parent
244ccef368
commit
5d0f729cbc
70
020_zsh.sh
70
020_zsh.sh
|
|
@ -263,5 +263,75 @@ alias ipython="_py_version"
|
|||
alias jupyter="_py_version"
|
||||
EOF
|
||||
|
||||
cat > .zsh_aliases.d/003-transfer.zsh <<'EOF'
|
||||
#
|
||||
# Defines transfer alias and provides easy command line file and folder sharing.
|
||||
#
|
||||
# Authors:
|
||||
# Remco Verhoef <remco@dutchcoders.io>
|
||||
#
|
||||
|
||||
curl --version 2>&1 > /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Could not find curl."
|
||||
return 1
|
||||
fi
|
||||
|
||||
transfer() {
|
||||
# check arguments
|
||||
if [ $# -eq 0 ];
|
||||
then
|
||||
echo -e "No arguments specified.\n\nUsage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# get temporarily filename, output is written to this file show progress can be showed
|
||||
tmpfile=$( mktemp -t transferXXX )
|
||||
|
||||
# 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 transferXXX.zip )
|
||||
cd $(dirname $file) && zip -r -q - $(basename $file) >> $zipfile
|
||||
curl --progress-bar --upload-file "$zipfile" "https://transfer.sh/$basefile.zip" >> $tmpfile
|
||||
rm -f $zipfile
|
||||
else
|
||||
# transfer file
|
||||
curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
|
||||
fi
|
||||
else
|
||||
# transfer pipe
|
||||
curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
|
||||
fi
|
||||
|
||||
# cat output link
|
||||
cat $tmpfile
|
||||
|
||||
# log file link
|
||||
APPLICATION="${0##*/}"
|
||||
RIGHTNOW="$(date)"
|
||||
EXPIRES="$(date -d "+14 days")"
|
||||
echo -e "$(cat "$tmpfile") - uploaded $RIGHTNOW - expires $EXPIRES\n" >> ~/$APPLICATION.log
|
||||
echo "See ~/$APPLICATION.log for all transfers."
|
||||
|
||||
# cleanup
|
||||
rm -f $tmpfile
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
chown -R root.root /usr/local/share/zsh/site-functions
|
||||
chmod -R 755 /usr/local/share/zsh/site-functions
|
||||
|
|
|
|||
Loading…
Reference in New Issue