summaryrefslogtreecommitdiff
path: root/mac/.local/bin/transadd
diff options
context:
space:
mode:
Diffstat (limited to 'mac/.local/bin/transadd')
-rwxr-xr-xmac/.local/bin/transadd29
1 files changed, 29 insertions, 0 deletions
diff --git a/mac/.local/bin/transadd b/mac/.local/bin/transadd
new file mode 100755
index 0000000..ffd8ded
--- /dev/null
+++ b/mac/.local/bin/transadd
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Mimeapp script for adding torrent to transmission-daemon, but will also start the daemon first if not running.
+
+# transmission-daemon sometimes fails to take remote requests in its first moments, hence the sleep.
+
+pidof transmission-daemon >/dev/null || (transmission-daemon && notify-send "💡 Starting transmission daemon..." && sleep 3 && pkill -RTMIN+22 "${STATUSBAR:-dwmblocks}")
+
+directory="$HOME/Torrents"
+
+[ "$1" = "-l" ] && {
+ URL=$(xclip -selection clipboard -o)
+ case "$URL" in
+ http://* | https://* | magnet:?*)
+ transmission-remote -a "$URL" && notify-send "🔽 Torrent added."
+ exit 0
+ ;;
+ *)
+ added_torrents=$(transmission-remote -l | grep -vE '^ID|Sum' | awk '{print $NF}' | sed 's/\.torrent$//')
+ filtered_files=$(ls "$directory"/*.torrent 2>/dev/null | sed "s|^$directory/||" | sed 's/\.torrent$//' | grep -vF "$added_torrents")
+ [ -n "$filtered_files" ] && {
+ choice=$(echo "$filtered_files" | dmenu -i -l 20 -p "Select Torrent:")
+ [ -n "$choice" ] && transmission-remote -a "$directory/$choice.torrent" && notify-send "🔽 Torrent added."
+ } || notify-send "🤷 No new torrent found."
+ ;;
+ esac
+} || {
+ transmission-remote -a "$@" && notify-send "🔽 Torrent added." "$TR_TORRENT_NAME"
+}