Skip to content

Instantly share code, notes, and snippets.

@not-ivy
Forked from Who23/statify
Last active April 7, 2021 05:29
Show Gist options
  • Save not-ivy/5d46219d2bee7b911976784433a3d656 to your computer and use it in GitHub Desktop.
Save not-ivy/5d46219d2bee7b911976784433a3d656 to your computer and use it in GitHub Desktop.
An updated version of statify that works in kitty terminal
#!/bin/bash
# My Fork of Who23's statify script, changed to kitty image protocol
# A script to display current spotify track info in a small terminal window
# this includes art, track name, and artist. All art/text centered
# Copyright 2020 Aditya Shrivastava
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# width in columns of the terminal window
WIDTH="$(tput cols)"
prev_info="\n"
clear
while true;
do
# polls spa every 10 secs to see if the track has changed
if [[ $prev_info != $(spa info) ]]
then
clear
curl -s $(spa art) > /tmp/art.jpg
kitty +icat /tmp/art.jpg
# get the track/artist & get how many spaces needed to center the text
track_name="$(spa name | cut -c -$((WIDTH - 2)))"
artist_name="$(spa artist | cut -c -$((WIDTH - 2)))"
track=${#track_name}
artist=${#artist_name}
track=$((WIDTH - track))
artist=$((WIDTH - artist))
track=$((track / 2))
artist=$((artist / 2))
# print the centered track name
printf "\033[2K"
for i in $(eval echo "{1..$track}"); do printf ' '; done
printf "$track_name\n"
# print the centered artist name
printf "\033[2K"
for j in $(eval echo "{1..$artist}"); do printf ' '; done
printf "$artist_name"
prev_info=$(spa info)
fi
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment