From 2df65000456641ad2aaed6fd139da874beb41869 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio <23226432+hyperreal64@users.noreply.github.com> Date: Fri, 31 May 2024 11:02:50 -0500 Subject: [PATCH] Use parallel --- qbth | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/qbth b/qbth index 9430a7b..b6f05ae 100755 --- a/qbth +++ b/qbth @@ -4,7 +4,7 @@ # Dependency check missing_deps=() -for bin in "gum" "jq" "lynx" "qbt"; do +for bin in "gum" "jq" "lynx" "parallel" "qbt"; do if ! test -x "$(command -v $bin)"; then missing_deps+=("$bin") fi @@ -19,20 +19,16 @@ fi function add_torrents() { torrents=("$@") - for url in "${torrents[@]}"; do - if qbt torrent add url "$url"; then - gum log -l info -t ansic "Added $(basename "$url")" - else - gum log -l error -t ansic "Error adding $(basename "$url")" - fi - done + parallel qbt torrent add url ::: "${torrents[@]}" + for url in "${torrents[@]}"; do gum log -l info "Added" "$(basename $url)"; done } function delete_torrents() { if test -n "$1"; then - echo "$1" | xargs -I _ sh -c "qbt torrent delete --with-files _ && gum log -l info -t ansic 'Deleted' _" + echo "$1" | parallel "qbt torrent delete --with-files {}" + echo "$1" | xargs -I _ gum log -l info "Deleted" _ else - gum log -l info -t ansic "Nothing to do." + gum log -l info "Nothing to do." fi }