added a transfer.sh plugin (#5854)
* added a transfer.sh plugin
created a function to easily upload files to transfer.sh file sharing site
Usage : transfer file.txt
* added README for transfer.sh plugin
* replaced transfer function with @nl5887 version
* updated transfer README.md
* modified the script to use tar command instead of zip
* Update README formatting
Co-authored-by: Remco Verhoef <remco@dutchcoders.io>
Diff
1diff --git a/plugins/transfer/README.md b/plugins/transfer/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..5fa0644451e06857c677adfb178e3c841f4a51e2
4--- /dev/null
5+++ b/plugins/transfer/README.md
6@@ -0,0 +1,24 @@
7+# `transfer` plugin
8+
9+[`transfer.sh`](https://transfer.sh) is an easy to use file sharing service from the command line
10+
11+## Usage
12+
13+Add `transfer` to your plugins array in your zshrc file:
14+```zsh
15+plugins=(... transfer)
16+```
17+
18+Then you can:
19+
20+- transfer a file:
21+
22+```zsh
23+transfer file.txt
24+```
25+
26+- transfer a whole directory (it will be automatically compressed):
27+
28+```zsh
29+transfer directory/
30+```
31diff --git a/plugins/transfer/transfer.plugin.zsh b/plugins/transfer/transfer.plugin.zsh
32new file mode 100644
33index 0000000000000000000000000000000000000000..7a7cd85ec1847af2354444de753f41e039227536
34--- /dev/null
35+++ b/plugins/transfer/transfer.plugin.zsh
36@@ -0,0 +1,67 @@
37+# transfer.sh Easy file sharing from the command line
38+# transfer Plugin
39+# Usage Example :
40+# > transfer file.txt
41+# > transfer directory/
42+
43+
44+
45+# Author:
46+# Remco Verhoef <remco@dutchcoders.io>
47+# https://gist.github.com/nl5887/a511f172d3fb3cd0e42d
48+# Modified to use tar command instead of zip
49+#
50+
51+curl --version 2>&1 > /dev/null
52+if [ $? -ne 0 ]; then
53+ echo "Could not find curl."
54+ return 1
55+fi
56+
57+transfer() {
58+ # check arguments
59+ if [ $# -eq 0 ];
60+ then
61+ echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
62+ return 1
63+ fi
64+
65+ # get temporarily filename, output is written to this file show progress can be showed
66+ tmpfile=$( mktemp -t transferXXX )
67+
68+ # upload stdin or file
69+ file=$1
70+
71+ if tty -s;
72+ then
73+ basefile=$(basename "$file" | sed -e 's/[^a-zA-Z0-9._-]/-/g')
74+
75+ if [ ! -e $file ];
76+ then
77+ echo "File $file doesn't exists."
78+ return 1
79+ fi
80+
81+ if [ -d $file ];
82+ then
83+ echo $file
84+ # tar directory and transfer
85+ tarfile=$( mktemp -t transferXXX.tar.gz )
86+ cd $(dirname $file) && tar -czf $tarfile $(basename $file)
87+ curl --progress-bar --upload-file "$tarfile" "https://transfer.sh/$basefile.tar.gz" >> $tmpfile
88+ rm -f $tarfile
89+ else
90+ # transfer file
91+ curl --progress-bar --upload-file "$file" "https://transfer.sh/$basefile" >> $tmpfile
92+ fi
93+ else
94+ # transfer pipe
95+ curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile
96+ fi
97+
98+ # cat output link
99+ cat $tmpfile
100+
101+ # cleanup
102+ rm -f $tmpfile
103+}