refactor: improve transfer shell function

This commit is contained in:
Bengt Brodersen
2018-06-25 12:50:10 +02:00
parent cdb97c4b64
commit e8fed79c74
2 changed files with 10 additions and 12 deletions

View File

@@ -30,11 +30,8 @@ $ curl -X PUT --upload-file nhgbhhj https://transfer.sh/test.txt/virustotal
Virusscan:
$ 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() {
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(){ 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;}
===
$ transfer test.txt