This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/statusbar/sb-torrent
2021-03-15 23:46:14 +01:00

28 lines
1001 B
Bash
Executable File

#!/usr/bin/env sh
######################################################################
# @author : swytch
# @file : sb-torrent
# @license : GPLv3
# @created : Sunday March 7, 2021 18:19:04 CET
#
# @description : torrent block for dwmblocks
######################################################################
pid="$(pidof transmission-daemon)"
[ -z "$pid" ] && exit
out="$(transmission-remote --list)"
cntd="$(echo "$out" | grep -e "Downloading" | wc -l)"
cntu="$(echo "$out" | grep -e "Seeding" | wc -l)"
cntud="$(echo "$out" | grep -e "Up & Down" | wc -l)"
cntd="$(expr $ctnd + $cntud)"
cntu="$(expr $cntu + $cntud)"
infos="$(echo "$out"| tail -n1)"
spdd="$(echo "$infos" | awk -F " " '{ printf "%.2f", $5/1000 }')"
spdu="$(echo "$infos" | awk -F " " '{ printf "%.2f", $4/1000 }')"
[ 0 -ne $cntd ] && down="$(printf "%s(%sM)" "$cntd" "$spdd")" || down="---"
[ 0 -ne $cntu ] && up="$(printf "%s(%sM)" "$cntu" "$spdu")" || up="---"
printf "  %s/%s " "$down" "$up"