aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-03-26 19:50:29 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-03-26 19:50:29 +1300
commit81bba32dc7c058c3d9096dbd2891b0d55b67a6c8 (patch)
treeb022cdc8c4e5541ceea2dae1a40e16f7eb6fdba4
downloadplz-81bba32dc7c058c3d9096dbd2891b0d55b67a6c8.tar.gz
plz-81bba32dc7c058c3d9096dbd2891b0d55b67a6c8.zip
Just committing this before I do much more with it
-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
+