~smlavine/scripts

ref: 5af0022d2df522079823605c7340e26ab9847202 scripts/src/mycmus -rwxr-xr-x 1.3 KiB
5af0022dSebastian LaVine dotfiles -> scripts 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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