#!/bin/sh
# Copyright (c) 2019-2021 Sebastian LaVine <mail@smlavine.com>
# Licensed under the MIT license. See MIT.txt for details.
#
# File: mycmus
# Description: Transmits info of current song playing in cmus using dmenu.
get_tag()
{
cmus-remote -C status | grep "^tag $1" | cut -d' ' -f3-
}
artist="$(get_tag artist)"
album="$(get_tag album)"
title="$(get_tag title)"
# If a field does not exist, don't add it to info.
# From best case to worst case, info could be one of the following:
# 1. artist - title (album)
# 2. artist - title
# 3. artist (album)
# 4. artist
# 5. title (album)
# 6. title
# 7. file
if [ "$artist" ]; then
info="$artist"
test "$title" && info="$info - $title"
test "$album" && info="$info ($album)"
elif [ "$title" ]; then
info="$title"
test "$album" && info="$info ($album)"
else
info="$(cmus-remote -C status | grep file | cut -d' ' -f2- | \
sed "s/^\/home\/$USER/~/")"
fi
# Yank: Pastes song info into system clipboard
# Duck: Opens web browser and searches song info on DuckDuckGo
# Skip: Skips the song, going to next one
# Repeat: Starts the song over from the beginning
case "$(printf "Yank\nDuck\nSkip\nRepeat" | dmenu -i -b -p "$info")" in
Yank) echo "$info" | xclip -selection c ;;
Duck) firefox "https://www.duckduckgo.com/$info" ;;
Skip) cmus-remote -n ;;
Repeat) cmus-remote -k 0 ;;
esac