From 81bba32dc7c058c3d9096dbd2891b0d55b67a6c8 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 26 Mar 2016 19:50:29 +1300 Subject: Just committing this before I do much more with it --- plz | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 plz (limited to 'plz') diff --git a/plz b/plz new file mode 100755 index 0000000..5a6100d --- /dev/null +++ b/plz @@ -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 + -- cgit v1.2.3