From b60641ca0c8b7f7f7701471c25ca815672ecb4cf Mon Sep 17 00:00:00 2001 From: Luxferre Date: Sat, 30 May 2026 17:09:42 +0300 Subject: [PATCH] added Musmaster port --- README.md | 1 + mus | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 mus diff --git a/README.md b/README.md index 8a86485..5bcf2bc 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ For POSIX shell compatible scripts, see the [sh-goodies](https://codeberg.org/lu ## List * [bmux](./bmux): a simple, dmux-like session manager in Bash on top of just dtach +* [Musmaster](./mus): find and play music quickly in any directory (bash port of [mus.sh](https://codeberg.org/luxferre/sh-goodies/src/branch/master/mus.sh)) * [YouStore](./ys): a way to securely store any set of files/directories inside a video * [1DLife](./1dlife): Jon Millen's 1D Game of Life in pure Bash * [Elem](./elem): Stephen Wolfram's elementary cellular automatons in pure Bash diff --git a/mus b/mus new file mode 100755 index 0000000..9ca9bf6 --- /dev/null +++ b/mus @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# Musmaster: find and play music in any directory (bash edition) +# Depends on find and fzf +# Created by Luxferre in 2026, released into the public domain + +[[ -z "$PLAYER" ]] && PLAYER='mpg123' +[[ -z "$FTYPES" ]] && FTYPES='mp3 MP3' +if [[ -z "$TAGDUMP" ]]; then + TAGDUMP='mpg123-id3dump -n {} | grep -E "^(Title|Artist|Album|Year|Comment|Genre):" | sort -u' +fi +PREVIEWCMD="[ -d {} ] && ls -1 {} || ([ {} != 'Quit' ] && $TAGDUMP)" +mdir="$1" +[[ -z "$mdir" ]] && mdir='.' +declare -a fargs=() muslist dirlist tracks +for ext in $FTYPES; do + fargs+=('-name' "*.$ext" '-o') +done +unset 'fargs[-1]' +cd "$mdir" +while true; do + mapfile -t muslist < <(find . -type f \( "${fargs[@]}" \)) + mapfile -t dirlist < <(dirname "${muslist[@]}" | sort -u) + IFS=$'\n' muslist=($(sort -u <<<"${muslist[*]} ${dirlist[*]}") Quit); unset IFS + src="$(printf '%s\n' "${muslist[@]}" | grep '\S' | fzf --tac --preview="$PREVIEWCMD" -0 -1)" + [[ "$src" = 'Quit' ]] && break + if [[ -n "$src" ]]; then + if [[ -d "$src" ]]; then + mapfile -t tracks < <(find "$src" -type f \( "${fargs[@]}" \) | sort -u) + $PLAYER "${tracks[@]}" + else + $PLAYER "$src" + fi + fi +done