aurorabbf5404
madd: show artist - title · album, bind SUPER+SHIFT+M
+22 −3
2 files changed
- M .config/hypr/source/keybinds.lua +1 −0
- M .local/bin/madd +21 −3
| @@ -47,6 +47,7 @@ hl.bind(mainMod .. " + SHIFT + P", hl.dsp.exec_cmd("hypr_screenshot.sh")) | |||
| 47 | 47 | ||
| 48 | 48 | -- Music Controls | |
| 49 | 49 | hl.bind(mainMod .. " + m", hl.dsp.exec_cmd(terminal .. " -e zsh -i -c \"rmptui\"")) | |
| 50 | + | hl.bind(mainMod .. " + SHIFT + m", hl.dsp.exec_cmd("madd </dev/null")) -- stdin is tty1 otherwise: madd would pick fzf | |
| 50 | 51 | hl.bind(mainMod .. " + p", hl.dsp.exec_cmd("mpc toggle")) | |
| 51 | 52 | hl.bind(mainMod .. " + period", hl.dsp.exec_cmd("mpc seek +10"), { repeating = true }) | |
| 52 | 53 | hl.bind(mainMod .. " + comma", hl.dsp.exec_cmd("mpc seek -10"), { repeating = true }) | |
| @@ -25,16 +25,34 @@ if ! mpc status >/dev/null 2>&1; then | |||
| 25 | 25 | exit 1 | |
| 26 | 26 | fi | |
| 27 | 27 | ||
| 28 | − | library=$(mpc listall) | |
| 28 | + | # One "Artist - Title · Album<TAB>file" line per track (the album makes typing an | |
| 29 | + | # album name list its songs). Untagged tracks fall back to the file name (minus | |
| 30 | + | # extension and a leading track number), and the artist is only prefixed when | |
| 31 | + | # that name doesn't already contain one. Singles (album = title) skip the album. | |
| 32 | + | library=$(mpc listall -f '%artist%\t%title%\t%album%\t%file%' | awk -F'\t' '{ | |
| 33 | + | artist = $1; title = $2; album = $3; file = $4 | |
| 34 | + | if (title == "") { | |
| 35 | + | title = file | |
| 36 | + | sub(/.*\//, "", title); sub(/\.[^.]*$/, "", title); sub(/^[0-9]+[.)]? *-? */, "", title) | |
| 37 | + | if (index(title, " - ")) artist = "" | |
| 38 | + | } | |
| 39 | + | line = artist != "" ? artist " - " title : title | |
| 40 | + | sub(/ - (Single|EP)$/, "", album) | |
| 41 | + | if (album != "" && album != title) line = line " · " album | |
| 42 | + | print line "\t" file | |
| 43 | + | }') | |
| 29 | 44 | if [ -z "$library" ]; then | |
| 30 | 45 | notify -u critical "MPD library is empty" "Try: mpc update" | |
| 31 | 46 | exit 1 | |
| 32 | 47 | fi | |
| 33 | 48 | ||
| 34 | 49 | if [ -t 0 ]; then | |
| 35 | − | filename=$(printf '%s\n' "$library" | fzf) | |
| 50 | + | filename=$(printf '%s\n' "$library" | fzf -d '\t' --with-nth 1 | cut -f2) | |
| 36 | 51 | else | |
| 37 | − | filename=$(printf '%s\n' "$library" | aurora-run -d -l 30 -p 'play: ') | |
| 52 | + | # aurora-run can't hide a column: show the names, map the index back to the file. | |
| 53 | + | n=$(printf '%s\n' "$library" | cut -f1 | aurora-run -d -l 30 -p 'play: ' --index) || exit 0 | |
| 54 | + | [ "$n" -ge 0 ] 2>/dev/null || exit 0 | |
| 55 | + | filename=$(printf '%s\n' "$library" | sed -n "$((n + 1))p" | cut -f2) | |
| 38 | 56 | fi | |
| 39 | 57 | ||
| 40 | 58 | # Cancelled (Esc): nothing to do. | |