| function transfer | |
| if test (count $argv) -eq 0 | |
| echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md" | |
| return 1 | |
| end | |
| ## get temporarily filename, output is written to this file show progress can be showed | |
| set tmpfile ( mktemp -t transferXXX ) | |
| ## upload stdin or file | |
| set file $argv[1] | |
| #if tty -s; | |
| #then | |
| set 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 test -d $file | |
| # zip directory and transfer | |
| set zipfile ( mktemp -t transferXXX.zip ) | |
| # echo (dirname $file) | |
| #cd (dirname $file) and echo (pwd) | |
| zip -r -q - $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 | |
| end | |
| #else | |
| # # transfer pipe | |
| # curl --progress-bar --upload-file "-" "https://transfer.sh/$file" >> $tmpfile | |
| #fi | |
| ## cat output link | |
| cat $tmpfile | |
| ## cleanup | |
| rm -f $tmpfile | |
| end |
| # | |
| # 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 "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 | |
| } | |
|
Thanks! Updated it to upload folders as well. |
orschiro
commented
Jan 5, 2015
|
This alias function works great with Zsh. Many thanks! |
Nygaardc
commented
May 23, 2015
|
I get the following error on both my RPI2 running Raspbian as well as on my Mac running OS X Yosemite: |
kyrias
commented
Jun 17, 2015
|
|
|
Thx, fixed it. |
jozsi
commented
Aug 3, 2015
|
On Mac OS X Yosemite the bash script will always create a file named I beleive line 8 should be:
|
|
thx, fixed |
GochoMugo
commented
Nov 6, 2015
|
Thanks for this! Already used here. |
bitbonsai
commented
Apr 2, 2016
|
Hi, I added a line on the bash version, to copy the link to clipboard... cat $tmpfile | pbcopy
cat $tmpfile |
rockymadden
commented
Apr 12, 2016
|
@bitbonsai, nice idea! Remove the newline at the end: |
s3y
commented
May 19, 2016
|
Is there a version of.Bat? |
priezz
commented
Aug 11, 2016
|
Nice. However quotes are missing around $file (4 occurrences). |
jyoo
commented
Aug 31, 2016
•
|
need to add a "-e" to echo for bash to interpret the newlines "\n". Thank you so much for this service. You are beyond awesome. Wish I found out about it sooner! Update: You can see my suggestions in my fork: https://gist.github.com/nl5887/a511f172d3fb3cd0e42d |
melmi
commented
Oct 1, 2016
|
I am using an older version of this alias. I tried to upload a file which its name contained brackets. I got an error because brackets have some special meaning for |
cheson
commented
Mar 6, 2017
|
Any idea why I get: syntax error near unexpected token 'filename' After adding the alias and trying to call it with any parameter? |
ysndr
commented
Apr 2, 2017
|
why not add |
tallinn-code
commented
May 9, 2017
|
Hello! How can one properly modify this shell script to add GPG encryption functionality ? It would be really nice to have this as an option. |
Nurrl
commented
May 11, 2017
|
on the website's version, the gist works well ;D |
Nurrl
commented
May 11, 2017
•
|
Agreeing with @tallinn-code, it could be great to implement a .trshrc file ;D |
HacKanCuBa
commented
May 13, 2017
|
There are several double quotes missing, plus other mistakes as in usage. transfer() {
# check arguments
if [ $# -ne 1 ];
then
echo -e "Wrong arguments specified. Usage:\ntransfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"
return 1
fi
# get temporary filename, output is written to this file so 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"
echo
# cleanup
rm -f "$tmpfile"
} |
xenefix
commented
May 15, 2017
|
Thanks @HacKanCuBa ! Had the same problem. |
PetrusKiendys
commented
Sep 26, 2017
|
Please consider pulling in my change: (currently no way to do a PR on gists.. :( ) |
Mike-T-Mitchell commentedDec 5, 2014
Thank you so much for taking the time to lay this out as clearly as possible. This functionality is awesome, and I definitely look forward to using it on a day-to-day basis!