all repos — dotfiles @ a8add29401610bae4a5012c8917368419824adf5

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 color0)"
 7light="$(xres color8)"
 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