refactor: improve transfer shell function
This commit is contained in:
@@ -44,7 +44,7 @@ include "includes/head.html"
|
|||||||
<br>$ curl --upload-file ./hello.txt https://transfer.sh/hello.txt https://transfer.sh/66nb8/hello.txt
|
<br>$ curl --upload-file ./hello.txt https://transfer.sh/hello.txt https://transfer.sh/66nb8/hello.txt
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<span class="code-title"># Using the alias</span>
|
<span class="code-title"># Using the shell function</span>
|
||||||
<br>$ transfer hello.txt
|
<br>$ transfer hello.txt
|
||||||
<br>##################################################### 100.0% https://transfer.sh/eibhM/hello.txt
|
<br>##################################################### 100.0% https://transfer.sh/eibhM/hello.txt
|
||||||
</code>
|
</code>
|
||||||
@@ -151,16 +151,17 @@ include "includes/head.html"
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-6 ">
|
<div class="col-md-6 ">
|
||||||
<h3>Add an alias to .bashrc or .zshrc <a href='https://gist.github.com/nl5887/a511f172d3fb3cd0e42d'>[gist]</a></h3>
|
<h3>Add shell function to .bashrc or .zshrc</a></h3>
|
||||||
<div class="terminal-top">
|
<div class="terminal-top">
|
||||||
</div>
|
</div>
|
||||||
<div class="terminal">
|
<div class="terminal">
|
||||||
<code>
|
<code>
|
||||||
<span class="code-title"># Add this to .bashrc or its equivalent</span>
|
<span class="code-title"># Add this to .bashrc or .zshrc or its equivalent</span>
|
||||||
<br/>transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi <br/>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; }
|
<br/>
|
||||||
|
transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,;;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;}
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<span class="code-title"># Now you can use transfer command</span>
|
<span class="code-title"># Now you can use transfer function</span>
|
||||||
<br>$ transfer hello.txt
|
<br>$ transfer hello.txt
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
@@ -237,12 +238,12 @@ include "includes/head.html"
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<h3>Send email with transfer link (uses alias)</h3>
|
<h3>Send email with transfer link (uses shell function)</h3>
|
||||||
<div class="terminal-top">
|
<div class="terminal-top">
|
||||||
</div>
|
</div>
|
||||||
<div class="terminal">
|
<div class="terminal">
|
||||||
<code>
|
<code>
|
||||||
<span class="code-title"># Transfer and send email with link (uses alias)</span>
|
<span class="code-title"># Transfer and send email with link (uses shell function)</span>
|
||||||
<br/>$ transfer /tmp/hello.txt | mail -s "Hello World" user@yourmaildomain.com
|
<br/>$ transfer /tmp/hello.txt | mail -s "Hello World" user@yourmaildomain.com
|
||||||
</code>
|
</code>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -30,11 +30,8 @@ $ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal
|
|||||||
Virusscan:
|
Virusscan:
|
||||||
$ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/scan
|
$ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/scan
|
||||||
|
|
||||||
Add alias to .bashrc or .zshrc:
|
Add shell function to .bashrc or .zshrc or its equivalent:
|
||||||
===
|
===
|
||||||
transfer() {
|
transfer(){ if [ $# -eq 0 ];then echo "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>">&2;return 1;fi;if tty -s;then file="$1";file_name=$(basename "$file");if [ ! -e "$file" ];then echo "$file: No such file or directory">&2;return 1;fi;if [ -d "$file" ];then file_name="$file_name.zip" ,;(cd "$file"&&zip -r -q - .)|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null,;;else cat "$file"|curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;else file_name=$1;curl --progress-bar --upload-file "-" "https://transfer.sh/$file_name"|tee /dev/null;fi;}
|
||||||
if [ $# -eq 0 ]; then echo -e "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"; fi; cat $tmpfile; rm -f $tmpfile; }
|
|
||||||
}
|
|
||||||
===
|
===
|
||||||
$ transfer test.txt
|
$ transfer test.txt
|
||||||
|
|||||||
Reference in New Issue
Block a user