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
This commit is contained in:
Lucas 2019-10-26 23:05:30 +00:00
parent 9b207887c1
commit a3ec887fb8
1 changed files with 12 additions and 3 deletions

View File

@ -9,12 +9,21 @@
# warranty. You should have received a copy of the CC0 Public Domain
# Dedication along with this software. If not, see
# <http://creativecommons.org/publicdomain/zero/1.0/>.
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" \