From a3ec887fb8f876891dc14aeca94f405098f23e3c Mon Sep 17 00:00:00 2001 From: Lucas Date: Sat, 26 Oct 2019 23:05:30 +0000 Subject: [PATCH] fetch: Don't mess stdout with progress bar Instead of using default ftp(1), if stdin is a tty, redirect ftp(1) stdout to the tty. This implies know you can safely do $ fetch ... | sxiv --- bin/fetch.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/fetch.sh b/bin/fetch.sh index 5dc100c..40e3cf8 100644 --- a/bin/fetch.sh +++ b/bin/fetch.sh @@ -9,12 +9,21 @@ # warranty. You should have received a copy of the CC0 Public Domain # Dedication along with this software. If not, see # . - -usage() { +usage() +{ printf "Usage: %s [-T] URL [URLs...]\n" "${0##*/}">&2 exit 1 } +fetch_cmd() +{ + if [ -t 0 ]; then + $torsocks ftp "$@" >$(tty) + else + $torsocks ftp "$@" + fi +} + torsocks=torsocks while getopts T flag; do case $flag in @@ -52,7 +61,7 @@ for url; do mkdir -p "$outdir" { - $torsocks ftp -o "$outdir/file" "$url" \ + fetch_cmd -o "$outdir/file" "$url" \ && printf "%s\n" "$url" >"$outdir/url" \ && printf "%s\n" "$name" >"$outdir/name" \ && printf "%s\n" "$url" >>"$everything" \