From bddd5d55b018f47b3b8387b53e7664346fda2497 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Jul 2022 16:14:26 -0500 Subject: Kill playing radio before playing another --- radio | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/radio b/radio index ba317b4..3c1fdda 100755 --- a/radio +++ b/radio @@ -101,21 +101,30 @@ _radio_play() { else station="$candidates" fi + + if [ -f "$RADIO_PID_FILE" ]; then + _radio_kill_impl + fi + echo >&2 "Playing $(echo "$station" | cut -f $_radio_desc)..." "$RADIO_PLAYER" "$(echo "$station" | cut -f $_radio_url)" >"$RADIO_STATUS_FILE" 2>&1 & echo $! >"$RADIO_PID_FILE" exit } +_radio_kill_impl() { + while xargs -a "$RADIO_PID_FILE" kill 2>/dev/null; do + printf '.' + done +} + _radio_kill() { if ! [ -f "$RADIO_PID_FILE" ]; then echo >&2 "I don't think radio is running." exit 1 fi printf >&2 '%s' "Killing radio" - while xargs -a "$RADIO_PID_FILE" kill 2>/dev/null; do - printf '.' - done + _radio_kill_impl rm "$RADIO_PID_FILE" echo exit -- cgit 1.4.1-21-gabe81