dotfiles/.i3blocks/mpd.new

64 lines
1.3 KiB
Bash
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
LENGHT=40
human_time() {
# Prends des secondes
local seconds="$1"
if [[ "$seconds" -lt 0 ]]
then
# Négatif = pas de temps à afficher
echo "--:--"
return
fi
# Calcule les minutes
local minutes=$(( $seconds / 60 ))
seconds=$(( $seconds % 60 ))
# Calcule les heures
local hours=$(( $minutes / 60 ))
minutes=$(( $minutes % 60 ))
if [[ "$hours" -ge 1 ]]
then
# Si on dépasse lheure affiche le temps en heures-minutes
printf "%02dh%02d\n" "$hours" "$minutes"
else
# Sinon en minutes-secondes
printf "%02d:%02d\n" "$minutes" "$seconds"
fi
return
}
# Boucle principale
while true
do
# Déclaration des variables
declare status
# État du serveur
if ! systemctl --user is-active mpd.service &>/dev/null
then
# Traitement particulier pour le cas où le service est coupé
status="off"
else
status="$(mpc status | sed -n '2p' | grep -Eo '^\[.*\]' | tr -d '[]')"
[[ -z status ]] && status="stopped"
fi
artist="$(mpc -f '%artist%' current)"
title="$(mpc -f '%title%' current)"
name="$(mpc -f '%name%' current)"
file="$(basename "$(mpc -f '%file%' current)")"
album="$(mpc -f '%album%' current)"
[[ -n "$artist" ]] && artist+=" "
( zscroll -n false -b "$(tput bold)$artist$(tput sgr0)" "${title:-${file}}" ) &
pid="$!"
mpc idle &>/dev/null
kill "$pid"
done