aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md20
-rw-r--r--completions/bass.fish12
-rw-r--r--functions/bass.fish95
3 files changed, 127 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..53c3ee0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+# bass
+
+A minimal wrapper around `mpc` and `beets` for the
+[fish](https://fishshell.com/) shell.
+
+[ListenBrainz](https://listenbrainz.org) integration requires
+[listenbrainz-mpd](https://codeberg.org/elomatreb/listenbrainz-mpd).
+
+## Installation
+
+Merge both `functions/` and `completions/` into your `~/.config/fish/` or
+`$XDG_CONFIG_HOME/fish/` directory.
+
+## Usage
+
+- `bass` will accept any command that `mpc` accepts. If no command is given, the playlist is printed.
+- `bass id` prints the MusicBrainz ID of the currently playing track.
+- `bass browse` opens the currently playing track on [MusicBrainz](https://musicbrainz.org/).
+- `bass love` marks the currently playing track as loved on ListenBrainz.
+- `bass hate` marks the currently playing track as hated on ListenBrainz.
diff --git a/completions/bass.fish b/completions/bass.fish
new file mode 100644
index 0000000..748954d
--- /dev/null
+++ b/completions/bass.fish
@@ -0,0 +1,12 @@
+set -l commands search find id browse love hate
+
+complete -c bass -f
+complete -c bass -n "not __fish_seen_subcommand_from $commands" -a search -d 'Search with a filter expression'
+complete -c bass -n "not __fish_seen_subcommand_from $commands" -a find -d 'Exact search with a filter expression'
+complete -c bass -n "not __fish_seen_subcommand_from $commands" -a id -d 'Print MusicBrainz ID of the currently playing track'
+complete -c bass -n "__fish_seen_subcommand_from id" -s a -l album -d 'Show ID of the album instead'
+complete -c bass -n "not __fish_seen_subcommand_from $commands" -a browse -d 'Open the currently playing track on MusicBrainz'
+complete -c bass -n "__fish_seen_subcommand_from browse" -s a -l album -d 'Open the album instead'
+complete -c bass -n "__fish_seen_subcommand_from browse" -s o -l open -d 'Open the file in the file manager instead'
+complete -c bass -n "not __fish_seen_subcommand_from $commands" -a love -d 'Mark the currently playing track as loved on ListenBrainz'
+complete -c bass -n "not __fish_seen_subcommand_from $commands" -a hate -d 'Mark the currently playing track as hated on ListenBrainz'
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