diff options
Diffstat (limited to 'plz')
-rwxr-xr-x | plz | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +self=plz + +declare -a confs +# shellcheck disable=SC2140 +confs=(/etc/"$self"rc "$HOME"/."$self"rc) + +for conf in "${confs[@]}" ; do + [[ -e "$conf" ]] || continue + source "$conf" +done + +usage() { + printf 'USAGE: %s TERM1 [TERM2 ...]\n' \ + "$self" >&2 +} + +if ! (($#)) ; then + usage >&2 + exit 1 +fi + +declare -a fargs +for term ; do + fargs[${#fargs[@]}]=-ipath + fargs[${#fargs[@]}]=\*"$term"\* +done + +shopt -s extglob + +declare -a matches +while IFS= read -d '' -r file ; do + [[ $file == *.@(flac|m4a|mp3|ogg) ]] || continue + matches[${#matches[@]}]=$file +done < <( + IFS='*' + find "${PLZ_DIR:-$HOME/Music}" \ + -type f "${fargs[@]}" -print0 +) + +case ${#matches[@]} in + 0) + printf '%s: No matches.\n' \ + "$self" >&2 + exit 1 + ;; + 1) + exec "${PLZ_PLAYER:-mpv}" -- "${matches[0]}" + ;; + *) + printf '%s\n' \ + "${matches[@]}" + ;; +esac + |