From a6f197a482db37f28dd51271affeb3a9c1db2c65 Mon Sep 17 00:00:00 2001
From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
Date: Mon, 4 Dec 2023 02:54:54 -0300
Subject: [PATCH] Fixes transfer() issues (#579)

- use subshell to avoid leaking vars to current shell
- use POSIX 'test -t' instead of tty
- have a single place to call curl
- echo the output url to add the carrier return when needed.
- use printf to process \n
- silence curl instead of teeing /dev/null

Co-authored-by: Andrea Spacca <andrea.spacca@gmail.com>
---
 README.md | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 86ad26c0..867a0da5 100644
--- a/README.md
+++ b/README.md
@@ -240,10 +240,10 @@ You need to create an OAuth Client id from console.cloud.google.com, download th
 
 ## Shell functions
 
-### Bash and zsh (multiple files uploaded as zip archive)
+### Bash, ash and zsh (multiple files uploaded as zip archive)
 ##### Add this to .bashrc or .zshrc or its equivalent
 ```bash
-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() (if [ $# -eq 0 ]; then printf "No arguments specified.\nUsage:\n transfer <file|directory>\n ... | transfer <file_name>\n">&2; return 1; fi; file_name=$(basename "$1"); if [ -t 0 ]; then file="$1"; if [ ! -e "$file" ]; then echo "$file: No such file or directory">&2; return 1; fi; if [ -d "$file" ]; then cd "$file" || return 1; file_name="$file_name.zip"; set -- zip -r -q - .; else set -- cat "$file"; fi; else set -- cat; fi; url=$("$@" | curl --silent --show-error --progress-bar --upload-file "-" "https://transfer.sh/$file_name"); echo "$url"; )
 ```
 
 #### Now you can use transfer function
-- 
GitLab