From d6ad9cb833c09c0b4edcd0830dfe5a98e2f28185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Mon, 6 Apr 2020 14:44:12 +0200 Subject: [PATCH] Added commands to script. --- play-lofi | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/play-lofi b/play-lofi index 9986cb6..05da14b 100755 --- a/play-lofi +++ b/play-lofi @@ -23,6 +23,19 @@ link_file="$XDG_CONFIG_HOME/lofi-link" +print_help() { + echo "USAGE: play-lofi [commands] +A program to play a lofi stream from Invidious (a YouTube proxy). When +given no options, it plays from the stream URL in '\$XDG_CONFIG_HOME/ +lofi-link'. If the file does not exist it will give you a selection of +streams to choose from. + +Commands: + new choose a new stream URL + set set stream URL + help show this help information" +} + new_link() { local results=$(curl -s "https://invidio.us/search?q=lofi+radio" | grep "

.*watch" | tr -d "\n" | tr -s " ") @@ -55,6 +68,35 @@ new_link() { echo $link > $link_file } +# argument parsing +if [ "$#" -eq "1" ] +then + case $1 in + "help") + print_help + exit 0;; + "new") + new_link;; + *) + echo "Unknown command '$1'. Run 'play-lofi help' for a list of commands." + exit 1;; + esac +elif [ "$#" -eq "2" ] +then + if [ "$1" = "set" ] + then + echo "$2" > $link_file + exit 0 + else + echo "Unknown command '$1 $2'. Run 'play-lofi help' for a list of commands." + exit 1 + fi +elif [ "$#" -gt "2" ] +then + echo "Too many arguments. Run 'play-lofi help' for a list of commands." + exit 1 +fi + # check for link file if ! [ -e "$link_file" ] then