From bed3c7c32118ff6c71cdae2cff76290300c48ea6 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 23 Jul 2018 13:59:35 +0200 Subject: [PATCH] Clean up transfer.sh code. Now is actually human readable instead of a snippet. --- zsh/.config/zsh/.zshrc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/zsh/.config/zsh/.zshrc b/zsh/.config/zsh/.zshrc index 3e9ddf8..379c98c 100644 --- a/zsh/.config/zsh/.zshrc +++ b/zsh/.config/zsh/.zshrc @@ -92,8 +92,23 @@ bindkey "${key[Home]}" beginning-of-line bindkey "${key[End]}" end-of-line # Transfer.sh plugin -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; }; alias transfer=transfer +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 + echo + rm -f $tmpfile +} +alias transfer=transfer ############################## # Autocomplete configuration #