From b4eb6c948fa5c758f5c4ebef2f6cdac7aca3afa5 Mon Sep 17 00:00:00 2001 From: Denis Lehmann Date: Mon, 15 Mar 2021 12:20:47 +0100 Subject: [PATCH] change interpreter to bash --- README.org | 35 +++++++++++++++++++++++------------ tyt | 21 ++++++++++++++++----- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/README.org b/README.org index 9b556bc..9e190a9 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,6 @@ * tyt :PROPERTIES: -:header-args: :tangle tyt :shebang "#!/bin/sh" +:header-args: :tangle tyt :shebang "#!/usr/bin/env bash" :END: Terminal YouTube (*tyt*) is a small bash script that lets you play YouTube videos by query from the command line. @@ -21,14 +21,25 @@ This will drop you into a shell with all requirements fulfilled. On the start of the script, it is checked if the dependencies are fulfilled. -#+begin_src sh +#+begin_src bash + missing_dependencies=false + if ! command -v jq &> /dev/null + then + echo -ne "\e[1mjq\e[0m was not found, please install it\n" + missing_dependencies=true + fi if ! command -v mpv &> /dev/null then - echo -ne "\e[1mmpv\e[0m was not found, please install it" - exit 1 - elif ! command -v youtube-dl &> /dev/null + echo -ne "\e[1mmpv\e[0m was not found, please install it\n" + missing_dependencies=true + fi + if ! command -v youtube-dl &> /dev/null + then + echo -ne "\e[1myoutube-dl\e[0m was not found, please install it\n" + missing_dependencies=true + fi + if [ "$missing_dependencies" = true ] then - echo -ne "\e[1myoutube-dl\e[0m was not found, please install it" exit 1 fi #+end_src @@ -37,7 +48,7 @@ On the start of the script, it is checked if the dependencies are fulfilled. This function prints the usage of the script. -#+begin_src sh +#+begin_src bash function print_usage { echo "tyt [ (-a* | --alternative) | (-i | --interactive) | (-m | --music) ] \"QUERY\"" } @@ -54,7 +65,7 @@ We have the following flags: Additionally we have exacly one mandatory quoted string as query. -#+begin_src sh +#+begin_src bash alternative=0 format="flac" interactive=false @@ -113,7 +124,7 @@ If the arguments match, print a greeter. Another greeter is printed if the flag =-m= is set. Make sure your terminal emulator supports Unicode to see the notes. -#+begin_src sh +#+begin_src bash if [ "$music" = false ] then echo -ne "\n \e[1m\ /\e[0m\n" @@ -134,7 +145,7 @@ To play a video, we need to get a valid URL. Since there are sometimes parsing errors of the JSON response, we use an endless loop to try until we get a valid response. The first /n/ URLs are saved if an alternative download is requested. -#+begin_src sh +#+begin_src bash i=0 if [ "$interactive" = true ] @@ -189,7 +200,7 @@ The first /n/ URLs are saved if an alternative download is requested. If the interactive flag is present, show the first ten results and query for a video to play. -#+begin_src sh +#+begin_src bash if [ "$interactive" = true ] then echo "" @@ -221,7 +232,7 @@ If the interactive flag is present, show the first ten results and query for a v Finally the video is played via mpv. If the =-m= flag is set, only the audio track is played. -#+begin_src sh +#+begin_src bash echo -ne "Playing: \e[32m\e[1m$title\e[0m (\e[33m\e[1m$uploader\e[0m)\n" if [ "$music" = true ] then diff --git a/tyt b/tyt index 7c39ed7..9b88586 100755 --- a/tyt +++ b/tyt @@ -1,11 +1,22 @@ -#!/bin/sh +#!/usr/bin/env bash +missing_dependencies=false +if ! command -v jq &> /dev/null +then + echo -ne "\e[1mjq\e[0m was not found, please install it\n" + missing_dependencies=true +fi if ! command -v mpv &> /dev/null then - echo -ne "\e[1mmpv\e[0m was not found, please install it" - exit 1 -elif ! command -v youtube-dl &> /dev/null + echo -ne "\e[1mmpv\e[0m was not found, please install it\n" + missing_dependencies=true +fi +if ! command -v youtube-dl &> /dev/null +then + echo -ne "\e[1myoutube-dl\e[0m was not found, please install it\n" + missing_dependencies=true +fi +if [ "$missing_dependencies" = true ] then - echo -ne "\e[1myoutube-dl\e[0m was not found, please install it" exit 1 fi