From 76c102944c8c164f2cf8908712b6c6a1d9fe5d70 Mon Sep 17 00:00:00 2001 From: Ilyes Kechidi Date: Wed, 23 Nov 2016 02:21:18 +0100 Subject: [PATCH 1/6] added a transfer.sh plugin created a function to easily upload files to transfer.sh file sharing site Usage : transfer file.txt --- plugins/transfer/transfer.plugin.zsh | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 plugins/transfer/transfer.plugin.zsh diff --git a/plugins/transfer/transfer.plugin.zsh b/plugins/transfer/transfer.plugin.zsh new file mode 100644 index 000000000..7d0d84bea --- /dev/null +++ b/plugins/transfer/transfer.plugin.zsh @@ -0,0 +1,7 @@ +# transfer.sh Easy file sharing from the command line +# transfer Plugin +# Usage Example : +# > transfer file.txt + +transfer() { if [ $# -eq 0 ]; then echo "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; } \ No newline at end of file From 8013d3d8a933b6bae3ed9ceb37bebb42cf28ea56 Mon Sep 17 00:00:00 2001 From: Ilyes Kechidi Date: Tue, 7 Feb 2017 14:40:21 +0100 Subject: [PATCH 2/6] added README for transfer.sh plugin --- plugins/transfer/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 plugins/transfer/README.md diff --git a/plugins/transfer/README.md b/plugins/transfer/README.md new file mode 100644 index 000000000..e14b94aa9 --- /dev/null +++ b/plugins/transfer/README.md @@ -0,0 +1,7 @@ +# `transfer.sh` plugin +transfer.sh is an easy file sharing service from the command line + +## Usage +Example +> transfer file.txt + From 845fdfaae0a913143d1ff03220a1bf1596871225 Mon Sep 17 00:00:00 2001 From: Ilyes Kechidi Date: Thu, 9 Feb 2017 02:28:33 +0100 Subject: [PATCH 3/6] replaced transfer function with @nl5887 version --- plugins/transfer/transfer.plugin.zsh | 62 +++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/plugins/transfer/transfer.plugin.zsh b/plugins/transfer/transfer.plugin.zsh index 7d0d84bea..796faa9a2 100644 --- a/plugins/transfer/transfer.plugin.zsh +++ b/plugins/transfer/transfer.plugin.zsh @@ -2,6 +2,64 @@ # transfer Plugin # Usage Example : # > transfer file.txt +# > transfer directory/ -transfer() { if [ $# -eq 0 ]; then echo "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; } \ No newline at end of file + + +# Author: +# Remco Verhoef +# https://gist.github.com/nl5887/a511f172d3fb3cd0e42d +# + +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 "No arguments specified. Usage:\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 + + # cleanup + rm -f $tmpfile +} \ No newline at end of file From 6cefe70ffc8f5d827a9b4341129114a843ceb248 Mon Sep 17 00:00:00 2001 From: Ilyes Kechidi Date: Thu, 9 Feb 2017 02:29:24 +0100 Subject: [PATCH 4/6] updated transfer README.md --- plugins/transfer/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/transfer/README.md b/plugins/transfer/README.md index e14b94aa9..9bf488d4e 100644 --- a/plugins/transfer/README.md +++ b/plugins/transfer/README.md @@ -4,4 +4,5 @@ transfer.sh is an easy file sharing service from the command line ## Usage Example > transfer file.txt +> transfer directory/ From c36474b7dfbe19c0628f6f21d8da40b535eeb5fb Mon Sep 17 00:00:00 2001 From: Ilyes Kechidi Date: Thu, 9 Feb 2017 19:41:09 +0100 Subject: [PATCH 5/6] modified the script to use tar command instead of zip --- plugins/transfer/transfer.plugin.zsh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/transfer/transfer.plugin.zsh b/plugins/transfer/transfer.plugin.zsh index 796faa9a2..7a7cd85ec 100644 --- a/plugins/transfer/transfer.plugin.zsh +++ b/plugins/transfer/transfer.plugin.zsh @@ -9,6 +9,7 @@ # Author: # Remco Verhoef # https://gist.github.com/nl5887/a511f172d3fb3cd0e42d +# Modified to use tar command instead of zip # curl --version 2>&1 > /dev/null @@ -43,11 +44,12 @@ transfer() { 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 + echo $file + # tar directory and transfer + tarfile=$( mktemp -t transferXXX.tar.gz ) + cd $(dirname $file) && tar -czf $tarfile $(basename $file) + curl --progress-bar --upload-file "$tarfile" "https://transfer.sh/$basefile.tar.gz" >> $tmpfile + rm -f $tarfile else # transfer file curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile From 3d8ee47c7a55119318d698a90f523e04fffb878d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Fri, 25 May 2018 20:44:56 +0200 Subject: [PATCH 6/6] Update README formatting --- plugins/transfer/README.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/plugins/transfer/README.md b/plugins/transfer/README.md index 9bf488d4e..5fa064445 100644 --- a/plugins/transfer/README.md +++ b/plugins/transfer/README.md @@ -1,8 +1,24 @@ -# `transfer.sh` plugin -transfer.sh is an easy file sharing service from the command line +# `transfer` plugin + +[`transfer.sh`](https://transfer.sh) is an easy to use file sharing service from the command line ## Usage -Example -> transfer file.txt -> transfer directory/ +Add `transfer` to your plugins array in your zshrc file: +```zsh +plugins=(... transfer) +``` + +Then you can: + +- transfer a file: + +```zsh +transfer file.txt +``` + +- transfer a whole directory (it will be automatically compressed): + +```zsh +transfer directory/ +```