better argument names and help message

This commit is contained in:
Siddharth Dushantha 2019-02-19 17:41:58 +01:00
parent 8a9e8bac34
commit b6d111d237
1 changed files with 30 additions and 13 deletions

43
kunst
View File

@ -4,33 +4,50 @@
# ┴ ┴└─┘┘└┘└─┘ ┴ # ┴ ┴└─┘┘└┘└─┘ ┴
# Created by Siddharth Dushantha # Created by Siddharth Dushantha
# VERSION=1.0 VERSION=1.0
COVER=/tmp/kunst.jpg COVER=/tmp/kunst.jpg
MUSIC_DIR=~/Music/ MUSIC_DIR=~/Music/
SIZE=250x250 SIZE=250x250
# Parse the arguments
options=$(getopt -o d:D:h --long size:,DIR:,help -- "$@") show_help() {
echo "usage: kunst [-h] [--size "px"] [--music_dir "path/to/dir"] [--version]"
echo " "
echo "┬┌─┬ ┬┌┐┌┌─┐┌┬┐"
echo "├┴┐│ ││││└─┐ │"
echo "┴ ┴└─┘┘└┘└─┘ ┴ $VERSION"
echo "Download and display album art or display embedded album art"
echo " "
echo "optional arguments:"
echo " -h, --help show this help message and exit"
echo " --size what size to display the album art in"
echo " --music_dir the music directory which MPD plays from"
echo " --version show the version of bum you are using"
}
# parse the arguments
options=$(getopt -o h --long size:,music_dir:,version,help -- "$@")
eval set -- "$options" eval set -- "$options"
while true; do while true; do
case "$1" in case "$1" in
-s|--size) --size)
shift; shift;
SIZE=$1 SIZE=$1
;; ;;
-D|--DIR) --music_dir)
shift; shift;
MUSIC_DIR=$1 MUSIC_DIR=$1
;; ;;
-h|--help) -h|--help)
echo "kunst" show_help
echo " -s, --size: Pass the size for the image.(Default: $SIZE)"
echo " -D, --DIR: Pass the Music directory that MPD plays from. (Default: $MUSIC_DIR)"
echo " -h, --help: Show this message and exit."
exit exit
;; ;;
--version)
echo $VERSION
exit
;;
--) --)
shift shift
break break
@ -59,7 +76,7 @@ is_connected() {
get_cover_online() { get_cover_online() {
# Check if connected to internet # check if connected to internet
is_connected is_connected
if [ $connected == false ];then if [ $connected == false ];then
@ -67,7 +84,7 @@ get_cover_online() {
return return
fi fi
# Try to get the album cover online from api.deezer.com # try to get the album cover online from api.deezer.com
API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'} API_URL="http://api.deezer.com/search/autocomplete?q=$(mpc current)" && API_URL=${API_URL//' '/'%20'}
# extract the albumcover from the json returned # extract the albumcover from the json returned
@ -113,7 +130,7 @@ update_cover() {
main() { main() {
# Flag to run some commands only once in the loop # flag to run some commands only once in the loop
FIRST_RUN=true FIRST_RUN=true
while true; do while true; do