Nettoyage i3blocks/mpd
This commit is contained in:
parent
2384a31bba
commit
b36e848cee
1 changed files with 22 additions and 21 deletions
|
@ -13,11 +13,11 @@ trap self-reset PIPE
|
|||
coproc nc -U /home/breizh/.mpd/socket
|
||||
IN=${COPROC[1]}
|
||||
OUT=${COPROC[0]}
|
||||
#echo "password xxx" >&${IN}
|
||||
sed '/^OK/q' <&$OUT &>/dev/null
|
||||
#echo "password xxx" >&"${IN}"
|
||||
sed '/^OK/q' <&"$OUT" &>/dev/null
|
||||
|
||||
# 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
|
||||
|
||||
human_time() {
|
||||
|
@ -27,12 +27,12 @@ human_time() {
|
|||
echo "--:--"
|
||||
return
|
||||
fi
|
||||
local minutes=$(( $seconds / 60 ))
|
||||
seconds=$(( $seconds % 60 ))
|
||||
local minutes=$(( seconds / 60 ))
|
||||
seconds=$(( seconds % 60 ))
|
||||
if [[ "$minutes" -ge 60 ]]
|
||||
then
|
||||
local hours=$(( $minutes / 60 ))
|
||||
minutes=$(( $minutes % 60 ))
|
||||
local hours=$(( minutes / 60 ))
|
||||
minutes=$(( minutes % 60 ))
|
||||
printf "%02dh%02d\n" "$hours" "$minutes"
|
||||
else
|
||||
printf "%02d:%02d\n" "$minutes" "$seconds"
|
||||
|
@ -41,8 +41,8 @@ human_time() {
|
|||
}
|
||||
|
||||
# Initialisation de l’état
|
||||
echo "status" >&$IN
|
||||
while read -t 1 -u $OUT output
|
||||
echo "status" >&"$IN"
|
||||
while read -t 1 -u "$OUT" output
|
||||
do
|
||||
[[ "$output" == "OK" ]] && break
|
||||
o[${output%%:*}]="${output##*: }"
|
||||
|
@ -59,21 +59,22 @@ do
|
|||
1|3)
|
||||
if [[ "${o["state"]}" == stop ]]
|
||||
then
|
||||
echo "play" >&${IN} || self-reset
|
||||
sed '/^OK$/q' <&$OUT &>/dev/null
|
||||
echo "play" >&"${IN}" || self-reset
|
||||
sed '/^OK$/q' <&"$OUT" &>/dev/null
|
||||
fi
|
||||
;;&
|
||||
2)
|
||||
if [[ "${o["state"]}" == stop ]]
|
||||
then
|
||||
echo "play" >&${IN} || self-reset
|
||||
echo "play" >&"${IN}" || self-reset
|
||||
else
|
||||
echo "pause" >&${IN} || self-reset
|
||||
echo "pause" >&"${IN}" || self-reset
|
||||
fi
|
||||
;;&
|
||||
1) echo "previous" >&${IN} || self-reset ;;&
|
||||
3) echo "next" >&${IN} || self-reset ;;&
|
||||
1|2|3) sed '/^OK$/q' <&$OUT &>/dev/null ;;
|
||||
1) echo "previous" >&"${IN}" || self-reset ;;&
|
||||
3) echo "next" >&"${IN}" || self-reset ;;&
|
||||
1|2|3) sed '/^OK$/q' <&"$OUT" &>/dev/null ;;
|
||||
4) I="I-2"; [[ "$I" -lt 0 ]] && I=0 ;;
|
||||
esac
|
||||
|
||||
# Réinitialisation de l’état
|
||||
|
@ -81,16 +82,16 @@ do
|
|||
declare -A o
|
||||
|
||||
# Récupération de l’état
|
||||
echo "status" >&$IN || self-reset
|
||||
while read -t 1 -u $OUT output
|
||||
echo "status" >&"$IN" || self-reset
|
||||
while read -t 1 -u "$OUT" output
|
||||
do
|
||||
[[ "$output" == "OK" ]] && break
|
||||
o[${output%%:*}]="${output##*: }"
|
||||
done
|
||||
|
||||
# Récupération des informations du morceau en cours
|
||||
echo "currentsong" >&$IN || self-reset
|
||||
while read -t 1 -u $OUT output
|
||||
echo "currentsong" >&"$IN" || self-reset
|
||||
while read -t 1 -u "$OUT" output
|
||||
do
|
||||
[[ "$output" == "OK" ]] && break
|
||||
o[${output%%:*}]="${output##*: }"
|
||||
|
@ -166,7 +167,7 @@ do
|
|||
time_total="${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//&/&}"
|
||||
bloc2="${bloc2//&/&}"
|
||||
|
|
Loading…
Reference in a new issue