-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_lyrics
executable file
·64 lines (54 loc) · 1.76 KB
/
show_lyrics
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Prints the lyric file corresponding to cmus's currently playing to the command line. Has the following possible arguments:
# (e)dit- Opens up filepath in $EDITOR
# (i)nstrumental - Creates file with 'Instrumental' written to it (appends in case used in error)
# (s)earch - Opens a Genius.com formatted url to search for lyrics then opens up filepath in $EDITOR
display_lyrics () {
clear
echo
echo "$title" - "$artist"
echo
echo
cat "$filepath" | less -F
echo
echo
echo "{Pass the (e)dit argument to show_lyrics to edit these lyrics}"
echo
}
lyrics_search () {
genius_search_url="$(echo "$artist"-"$title-lyrics" |
tr '[:upper:]' '[:lower:]' |
sed 's/ /-/g' |
sed "s/'//g" |
sed 's/\.//g' |
sed 's|/|-|g' |
sed 's/\?//g' |
sed 's/./\U&/')"
$BROWSER "https://genius.com/$genius_search_url"
}
if [ -z "$(pidof cmus)" ] ; then
echo "cmus not currently running" && exit 0
fi
lyrics_directory=~/music/lyrics/
currently_playing="$(cmus-remote -C status)"
title=$(echo "$currently_playing" | grep -m 1 'tag title' | cut -d ' ' -f 3-)
artist=$(echo "$currently_playing" | grep -m 1 'tag artist' | cut -d ' ' -f 3-)
filepath=""$lyrics_directory""$artist"-"$title""
if [[ $1 ]] ; then
case "$1" in
"e"|"edit")
$EDITOR "$filepath" && display_lyrics
;;
"i"|"instrumental")
echo "Instrumental" >> "$filepath" && display_lyrics
;;
"s"|"search")
lyrics_search && $EDITOR "$filepath" && display_lyrics
esac
elif [[ -e "$filepath" ]] ; then
display_lyrics
else
clear
echo "No lyrics for "$title" - "$artist" found"
echo "Pass (e)dit, (i)nstrumental or (s)earch to show_lyrics"
fi