From 78c2c95b0e570d821e5715ceaede2bedf54c631b Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sat, 23 Dec 2017 10:08:55 +0100 Subject: [PATCH] qutebrowser: Start transmission-daemon on demand --- .config/qutebrowser/config.py | 4 ++-- .local/bin/transmission-auto | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 .local/bin/transmission-auto diff --git a/.config/qutebrowser/config.py b/.config/qutebrowser/config.py index df962e64..6d824432 100644 --- a/.config/qutebrowser/config.py +++ b/.config/qutebrowser/config.py @@ -46,8 +46,8 @@ c.url.searchengines = { } config.bind(',v', 'spawn mpv {url}') -config.bind(',t', 'hint links spawn transmission-remote -a {hint-url}') -config.bind(',T', 'hint -r links spawn transmission-remote -a {hint-url}') +config.bind(',t', 'hint links spawn transmission-auto -a {hint-url}') +config.bind(',T', 'hint -r links spawn transmission-auto -a {hint-url}') config.bind('yy', 'yank -s') config.bind('yY', 'yank') config.bind('yd', 'yank -s domain') diff --git a/.local/bin/transmission-auto b/.local/bin/transmission-auto new file mode 100755 index 00000000..8fa2be06 --- /dev/null +++ b/.local/bin/transmission-auto @@ -0,0 +1,33 @@ +#!/bin/sh + +if [ "$1" = "-h" ]; then + cat <&2 +Usage: ${0##*/} [OPTIONS] + +With no argument, open Transmission's interface. Otherwise, run +transmission-remote with the provided options. + +In both cases if transmission-daemon is not running it will be started +beforehand. + +EOF + exit +fi + +for i in transmission-daemon transmission-remote ; do + if ! command -v $i >/dev/null 2>&1; then + echo >&2 "'$i' not found" + exit 1 + fi +done + +## The command is often displayed as transmission-da. +## The 'sleep' is needed here to give the daemon some time to start. 1 sec +## should be enough on most system. +ps -U "$USER" -o comm= | grep -q transmission-da || { transmission-daemon && echo "Daemon started" && sleep 1 ; } + +if [ $# -eq 0 ]; then + $BROWSER http://localhost:9091/ +else + transmission-remote "$@" +fi