aboutsummaryrefslogtreecommitdiff
path: root/plz
diff options
context:
space:
mode:
Diffstat (limited to 'plz')
-rwxr-xr-xplz56
1 files changed, 56 insertions, 0 deletions
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
+