From b55baa6af75f83da3a820cce258c9f5564a08f2c Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Tue, 12 May 2020 12:09:43 +0200 Subject: [PATCH] Add 'torrent' module for bar and 'torradd' script --- .local/bin/scripts/dbar | 5 +++-- .local/bin/scripts/dwmbar/torrent | 18 ++++++++++++++++++ .local/bin/scripts/torradd | 6 ++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100755 .local/bin/scripts/dwmbar/torrent create mode 100755 .local/bin/scripts/torradd diff --git a/.local/bin/scripts/dbar b/.local/bin/scripts/dbar index da9c1c8..670c044 100755 --- a/.local/bin/scripts/dbar +++ b/.local/bin/scripts/dbar @@ -1,16 +1,17 @@ #!/bin/sh sym="|" +[ "$(transmission-remote -l | grep %)" ] && delay="10s" || delay="1m" cd "$HOME/.local/bin/scripts/dwmbar/" || exit 1 status() { - echo "$(./disk) $sym $(./internet) $sym $(./lamp) $sym $(./music) $sym" \ + echo "$(./torrent) $sym $(./disk) $sym $(./internet) $sym $(./lamp) $sym $(./music) $sym" \ "$(./alsa) $sym $(./packages) $sym $(./date) $sym $(./clock)" } while :; do xsetroot -name " $(status | tr '\n' ' ')" - sleep 1m + sleep "$delay" done diff --git a/.local/bin/scripts/dwmbar/torrent b/.local/bin/scripts/dwmbar/torrent new file mode 100755 index 0000000..bf87852 --- /dev/null +++ b/.local/bin/scripts/dwmbar/torrent @@ -0,0 +1,18 @@ +#!/bin/sh + +echo "" + +data() { transmission-remote -l | grep %; } +[ ! "$(data)" ] && { echo N; exit 1; } + +per="$(data | awk '{ print $2 }')" +[ "${per%?}" != 100 ] && echo "$per" || echo "" + +data | \ + sed " + s/.*Stopped.*//g; + s/.*Seeding.*//g; + s/.*Idle.*//g; + s/.*Uploading.*//g; + s/.*%.*//g + " diff --git a/.local/bin/scripts/torradd b/.local/bin/scripts/torradd new file mode 100755 index 0000000..1badc7d --- /dev/null +++ b/.local/bin/scripts/torradd @@ -0,0 +1,6 @@ +#!/bin/sh + +pidof transmission-daemon >/dev/null || \ + (transmission-daemon && notify-send "Starting transmission daemon...") + +transmission-remote -a "$@" && notify-send " Torrent added."