blob: 342ccdd207d017ee8119010e03a2a64353e8b077 (
plain) (
tree)
|
|
#!/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 < <(
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
|