diff options
author | Case Duckworth | 2022-07-07 13:53:54 -0500 |
---|---|---|
committer | Case Duckworth | 2022-07-07 13:53:54 -0500 |
commit | 61fda4d6f25f3c3eae0a35a9265e85ce91c1918a (patch) | |
tree | f5d0df84886f9bd656c95a09a4a76e156d42d98b | |
parent | Add -s/-S options for status (diff) | |
download | radio-61fda4d6f25f3c3eae0a35a9265e85ce91c1918a.tar.gz radio-61fda4d6f25f3c3eae0a35a9265e85ce91c1918a.zip |
Move main to the top
-rwxr-xr-x | radio | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/radio b/radio index 2078dfe..ba317b4 100755 --- a/radio +++ b/radio | |||
@@ -43,6 +43,49 @@ EOF | |||
43 | exit ${1:-0} | 43 | exit ${1:-0} |
44 | } | 44 | } |
45 | 45 | ||
46 | main() { | ||
47 | while getopts :kKsShel: opt; do | ||
48 | case $opt in | ||
49 | h) usage ;; | ||
50 | k) _radio_kill ;; | ||
51 | K) | ||
52 | pkill "$RADIO_PLAYER" | ||
53 | exit | ||
54 | ;; | ||
55 | e) _radio_edit ;; | ||
56 | s) _radio_status ;; | ||
57 | S) _radio_status -f ;; | ||
58 | l) _radio_list "$OPTARG" ;; | ||
59 | :) | ||
60 | case "$OPTARG" in | ||
61 | l) _radio_list ;; | ||
62 | *) | ||
63 | echo >&2 "Option -$OPTARG requires an argument" | ||
64 | exit 1 | ||
65 | ;; | ||
66 | esac | ||
67 | ;; | ||
68 | \?) | ||
69 | echo >&2 "Uknown option: -$OPTARG" | ||
70 | exit 1 | ||
71 | ;; | ||
72 | esac | ||
73 | done | ||
74 | shift $((OPTIND - 1)) | ||
75 | _radio_play "$@" | ||
76 | } | ||
77 | |||
78 | _radio_status() { | ||
79 | if [ "x$1" = x-f ]; then | ||
80 | follow=-f | ||
81 | else | ||
82 | follow= | ||
83 | fi | ||
84 | tail -n4 $follow "$RADIO_STATUS_FILE" | ||
85 | echo | ||
86 | exit | ||
87 | } | ||
88 | |||
46 | _radio_play() { | 89 | _radio_play() { |
47 | candidates="$(sed -e 1d -e '/^#/d' "$RADIO_STATIONS" | grep -i "$1")" | 90 | candidates="$(sed -e 1d -e '/^#/d' "$RADIO_STATIONS" | grep -i "$1")" |
48 | if [ -z "$candidates" ]; then | 91 | if [ -z "$candidates" ]; then |
@@ -98,30 +141,4 @@ _radio_list() { | |||
98 | exit | 141 | exit |
99 | } | 142 | } |
100 | 143 | ||
101 | main() { | ||
102 | while getopts :khel: opt; do | ||
103 | case $opt in | ||
104 | h) usage ;; | ||
105 | k) _radio_kill ;; | ||
106 | e) _radio_edit ;; | ||
107 | l) _radio_list "$OPTARG" ;; | ||
108 | :) | ||
109 | case "$OPTARG" in | ||
110 | l) _radio_list ;; | ||
111 | *) | ||
112 | echo >&2 "Option -$OPTARG requires an argument" | ||
113 | exit 1 | ||
114 | ;; | ||
115 | esac | ||
116 | ;; | ||
117 | \?) | ||
118 | echo >&2 "Uknown option: -$OPTARG" | ||
119 | exit 1 | ||
120 | ;; | ||
121 | esac | ||
122 | done | ||
123 | shift $((OPTIND - 1)) | ||
124 | _radio_play "$@" | ||
125 | } | ||
126 | |||
127 | main "$@" | 144 | main "$@" |