all repos — dotfiles @ 2f6996a1a7fbdbaab650c5c09cd5fb18b5204ef6

my *nix dotfiles

bin/np.sh (view raw)

 1#!/usr/bin/env bash
 2# now playing
 3# requires the last.fm API key
 4
 5source ~/.lastfm    # `export API_KEY="<key>"`
 6fg="$(xres color8)"
 7light="$(xres color15)"
 8
 9USER="icyphox"
10URL="http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks"
11URL+="&user=$USER&api_key=$API_KEY&format=json&limit=1&nowplaying=true"
12NOTPLAYING=" "
13RES="$(curl -s $URL)"
14NOWPLAYING=$(jq '.recenttracks.track[0]."@attr".nowplaying' <<< "$RES" | tr -d '"')
15
16
17if [[ "$NOWPLAYING" = "true" ]]
18then
19	TRACK=$(jq '.recenttracks.track[0].name' <<< "$RES" | tr -d '"')
20	ARTIST=$(jq '.recenttracks.track[0].artist."#text"' <<< "$RES" | tr -d '"')
21	echo -ne "%{F$light}$TRACK %{F$fg}by $ARTIST"
22else
23	echo -ne "$NOTPLAYING"
24fi