#!/bin/sh TRACKS="/mnt/storage/radio/music/" PLAYLISTS="/mnt/storage/radio/playlists/" CURRENT="/mnt/storage/radio/playlists/current.m3u" choose_playlist() { chosen=$(find "$PLAYLISTS" -type f -name "*.m3u" | fzf) ln -sf "$chosen" "$CURRENT" } edit_playlist() { vim "$(readlink "$CURRENT")" } create_playlist() { clear read -p "name the playlist: " new touch "$PLAYLISTS$new.m3u" echo "#EXTM3U" > "$PLAYLISTS$new.m3u" target=$("$PLAYLISTS$new.m3u") selected=$(cd "$TRACKS" && find . -type f -iname "*.ogg" | sed 's|^\./||' | fzf -m) printf "%s\n" "$selected" | sed "s|^|$TRACKS|" >> "$target" } add_to_playlist() { target=$(readlink "$CURRENT") selected=$(cd "$TRACKS" && find . -type f -iname "*.ogg" | sed 's|^\./||' | fzf -m) printf "%s\n" "$selected" | sed "s|^|$TRACKS|" >> "$target" } reload_playlist() { kill -HUP "$(pgrep -f ezstream)" } menu() { echo "Now playing: $(basename "$(readlink "$CURRENT")")" echo "1) Choose playlist" echo "2) Create playlist" echo "3) Add to playlist" echo "4) Edit playlist" echo "9) Reload playlist" echo "0) Exit" read -p "Select an option: " opt case "$opt" in 1) choose_playlist ;; 2) create_playlist ;; 3) add_to_playlist ;; 4) edit_playlist ;; 9) reload_playlist ;; 0) exit ;; *) echo "Invalid option" ;; esac } while true; do clear menu done