From bf5e99aeba0db77d280c97a956763a9163ec31e9 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Sun, 10 Mar 2024 15:29:06 +0100 Subject: Initial commit --- functions/bass.fish | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 functions/bass.fish (limited to 'functions') diff --git a/functions/bass.fish b/functions/bass.fish new file mode 100644 index 0000000..dee4074 --- /dev/null +++ b/functions/bass.fish @@ -0,0 +1,95 @@ +function bass + switch "$argv[1]" + case search find + __bass_print (__bass_mpc $argv) + case id + __bass_mbid $argv + case browse + __bass_browse $argv + case love + mpc sendmessage listenbrainz_feedback love + case hate + mpc sendmessage listenbrainz_feedback hate + case "" + __bass_print -p (__bass_mpc playlist) + case "*" + mpc $argv + end +end + +function __bass_print + argparse "p/playlist" -- $argv + or return 1 + + for line in $argv + set -l data (string split \t $line) + set -l artist (__bass_trim $data[1]) + set -l album (__bass_trim $data[2]) + set -l title (__bass_trim $data[3]) + set -l file $data[4] + set -l position $data[5] + + if not isatty stdout + echo $file + else if set -q _flag_playlist + set -l current (mpc -f "%position%" current) + + if test "$position" = "$current" + echo -n "▶ " + else + echo -n " " + end + + __bass_print_track $title $artist $album + else + __bass_print_track $title $artist $album + end + end +end + +function __bass_trim + set -l length (string length $argv[1]) + if test $length -gt 39 + echo (string sub --length 39 $argv[1])… + else + echo $argv[1] + end +end + +function __bass_print_track + set_color blue + echo -n $argv[1] + set_color normal + echo " ꞏ $argv[2] ꞏ $argv[3]" +end + +function __bass_mpc + set -l format "%artist%\t%album%\t%title%\t%file%\t%position%" + mpc -f $format $argv +end + +function __bass_browse + argparse "a/album" "o/open" -- $argv + or return 1 + + set -l id (__bass_mbid $_flag_album) + or return 1 + + beet browse $_flag_album $_flag_open $id +end + +function __bass_mbid + argparse "a/album" -- $argv + or return 1 + + set -l ids (string split \t (mpc -f "%musicbrainz_trackid%\t%musicbrainz_albumid%" current)) + if test $status -ne 0 + return 1 + end + + if not set -q _flag_album + echo "mb_trackid:$ids[1]" + else + echo "mb_albumid:$ids[2]" + end +end -- cgit v1.2.3-2-gb3c3