From 61fda4d6f25f3c3eae0a35a9265e85ce91c1918a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Jul 2022 13:53:54 -0500 Subject: Move main to the top --- radio | 69 ++++++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/radio b/radio index 2078dfe..ba317b4 100755 --- a/radio +++ b/radio @@ -43,6 +43,49 @@ EOF exit ${1:-0} } +main() { + while getopts :kKsShel: opt; do + case $opt in + h) usage ;; + k) _radio_kill ;; + K) + pkill "$RADIO_PLAYER" + exit + ;; + e) _radio_edit ;; + s) _radio_status ;; + S) _radio_status -f ;; + l) _radio_list "$OPTARG" ;; + :) + case "$OPTARG" in + l) _radio_list ;; + *) + echo >&2 "Option -$OPTARG requires an argument" + exit 1 + ;; + esac + ;; + \?) + echo >&2 "Uknown option: -$OPTARG" + exit 1 + ;; + esac + done + shift $((OPTIND - 1)) + _radio_play "$@" +} + +_radio_status() { + if [ "x$1" = x-f ]; then + follow=-f + else + follow= + fi + tail -n4 $follow "$RADIO_STATUS_FILE" + echo + exit +} + _radio_play() { candidates="$(sed -e 1d -e '/^#/d' "$RADIO_STATIONS" | grep -i "$1")" if [ -z "$candidates" ]; then @@ -98,30 +141,4 @@ _radio_list() { exit } -main() { - while getopts :khel: opt; do - case $opt in - h) usage ;; - k) _radio_kill ;; - e) _radio_edit ;; - l) _radio_list "$OPTARG" ;; - :) - case "$OPTARG" in - l) _radio_list ;; - *) - echo >&2 "Option -$OPTARG requires an argument" - exit 1 - ;; - esac - ;; - \?) - echo >&2 "Uknown option: -$OPTARG" - exit 1 - ;; - esac - done - shift $((OPTIND - 1)) - _radio_play "$@" -} - main "$@" -- cgit 1.4.1-21-gabe81