Nettoyage i3blocks/mpd

This commit is contained in:
Breizh 2022-08-13 01:38:52 +02:00
parent 2384a31bba
commit b36e848cee

View file

@ -13,11 +13,11 @@ trap self-reset PIPE
coproc nc -U /home/breizh/.mpd/socket coproc nc -U /home/breizh/.mpd/socket
IN=${COPROC[1]} IN=${COPROC[1]}
OUT=${COPROC[0]} OUT=${COPROC[0]}
#echo "password xxx" >&${IN} #echo "password xxx" >&"${IN}"
sed '/^OK/q' <&$OUT &>/dev/null sed '/^OK/q' <&"$OUT" &>/dev/null
# Initialisation des valeurs par défaut et des fonctions # Initialisation des valeurs par défaut et des fonctions
declare -i SCROLL=40 I=0 declare -i SCROLL=50 I=0
declare -- artist song oldfile declare -- artist song oldfile
human_time() { human_time() {
@ -27,12 +27,12 @@ human_time() {
echo "--:--" echo "--:--"
return return
fi fi
local minutes=$(( $seconds / 60 )) local minutes=$(( seconds / 60 ))
seconds=$(( $seconds % 60 )) seconds=$(( seconds % 60 ))
if [[ "$minutes" -ge 60 ]] if [[ "$minutes" -ge 60 ]]
then then
local hours=$(( $minutes / 60 )) local hours=$(( minutes / 60 ))
minutes=$(( $minutes % 60 )) minutes=$(( minutes % 60 ))
printf "%02dh%02d\n" "$hours" "$minutes" printf "%02dh%02d\n" "$hours" "$minutes"
else else
printf "%02d:%02d\n" "$minutes" "$seconds" printf "%02d:%02d\n" "$minutes" "$seconds"
@ -41,8 +41,8 @@ human_time() {
} }
# Initialisation de létat # Initialisation de létat
echo "status" >&$IN echo "status" >&"$IN"
while read -t 1 -u $OUT output while read -t 1 -u "$OUT" output
do do
[[ "$output" == "OK" ]] && break [[ "$output" == "OK" ]] && break
o[${output%%:*}]="${output##*: }" o[${output%%:*}]="${output##*: }"
@ -59,21 +59,22 @@ do
1|3) 1|3)
if [[ "${o["state"]}" == stop ]] if [[ "${o["state"]}" == stop ]]
then then
echo "play" >&${IN} || self-reset echo "play" >&"${IN}" || self-reset
sed '/^OK$/q' <&$OUT &>/dev/null sed '/^OK$/q' <&"$OUT" &>/dev/null
fi fi
;;& ;;&
2) 2)
if [[ "${o["state"]}" == stop ]] if [[ "${o["state"]}" == stop ]]
then then
echo "play" >&${IN} || self-reset echo "play" >&"${IN}" || self-reset
else else
echo "pause" >&${IN} || self-reset echo "pause" >&"${IN}" || self-reset
fi fi
;;& ;;&
1) echo "previous" >&${IN} || self-reset ;;& 1) echo "previous" >&"${IN}" || self-reset ;;&
3) echo "next" >&${IN} || self-reset ;;& 3) echo "next" >&"${IN}" || self-reset ;;&
1|2|3) sed '/^OK$/q' <&$OUT &>/dev/null ;; 1|2|3) sed '/^OK$/q' <&"$OUT" &>/dev/null ;;
4) I="I-2"; [[ "$I" -lt 0 ]] && I=0 ;;
esac esac
# Réinitialisation de létat # Réinitialisation de létat
@ -81,16 +82,16 @@ do
declare -A o declare -A o
# Récupération de létat # Récupération de létat
echo "status" >&$IN || self-reset echo "status" >&"$IN" || self-reset
while read -t 1 -u $OUT output while read -t 1 -u "$OUT" output
do do
[[ "$output" == "OK" ]] && break [[ "$output" == "OK" ]] && break
o[${output%%:*}]="${output##*: }" o[${output%%:*}]="${output##*: }"
done done
# Récupération des informations du morceau en cours # Récupération des informations du morceau en cours
echo "currentsong" >&$IN || self-reset echo "currentsong" >&"$IN" || self-reset
while read -t 1 -u $OUT output while read -t 1 -u "$OUT" output
do do
[[ "$output" == "OK" ]] && break [[ "$output" == "OK" ]] && break
o[${output%%:*}]="${output##*: }" o[${output%%:*}]="${output##*: }"
@ -166,7 +167,7 @@ do
time_total="${o["time"]#*:}" time_total="${o["time"]#*:}"
time_left="${time_total:-${o["duration"]%.*}} - ${time_elapsed:-${o["Time"]}}" time_left="${time_total:-${o["duration"]%.*}} - ${time_elapsed:-${o["Time"]}}"
time="[$(human_time ${time_elapsed}) $(human_time ${time_left}) $(human_time ${time_total})]" time="[$(human_time "${time_elapsed}") $(human_time "${time_left}") $(human_time "${time_total}")]"
bloc1="${bloc1//&/&amp;}" bloc1="${bloc1//&/&amp;}"
bloc2="${bloc2//&/&amp;}" bloc2="${bloc2//&/&amp;}"