fixes MPD

This commit is contained in:
Breizh 2019-06-14 09:42:47 +02:00
parent e9773bfa93
commit 99b61aee79
6 changed files with 117 additions and 64 deletions

View file

@ -108,10 +108,10 @@ bindsym XF86AudioMute exec --no-startup-id BLOCK_BUTTON=2 ${HOME}/.i3blocks/volu
bindsym XF86AudioMicMute exec --no-startup-id BLOCK_BUTTON=2 BLOCK_INSTANCE=Capture ${HOME}/.i3blocks/volume && pkill -RTMIN+10 i3blocks
# Media controls
bindsym XF86AudioNext exec --no-startup-id mocp -f
bindsym XF86AudioPrev exec --no-startup-id mocp -r
bindsym XF86AudioPlay exec --no-startup-id mocp -G
bindsym XF86AudioStop exec --no-startup-id mocp -s
bindsym XF86AudioNext exec --no-startup-id mpc next
bindsym XF86AudioPrev exec --no-startup-id mpc prev
bindsym XF86AudioPlay exec --no-startup-id mpc toggle
bindsym XF86AudioStop exec --no-startup-id mocp stop
# LEDs controls

View file

@ -38,14 +38,12 @@ markup=pango
# see the script for details.
[cpu_usage]
#label=
label=cpu
interval=1
#min_width= 99.99%
#separator=false
[load_average]
#label=
label=load
interval=5
# Temperature
@ -53,32 +51,32 @@ interval=5
# Support multiple chips, though lm-sensors.
# The script may be called with -w and -c switches to specify thresholds,
# see the script for details.
[temperature]
#label=
label=cpu
instance=coretemp-isa-0000
interval=3
separator=false
[temperature]
label=gpu
instance=radeon-pci-0300
interval=3
#[temperature]
##label=
#label=cpu
#instance=coretemp-isa-0000
#interval=3
#separator=false
#
#[temperature]
#label=gpu
#instance=radeon-pci-0300
#interval=3
# Memory usage
#
# The type defaults to "mem" if the instance is not specified.
[memory]
label=ram
separator=false
#separator=false
interval=2
#min_width=RAM 99.99%
[memory]
label=swap
instance=swap
#separator=false
interval=2
#min_width=swap 99.9%
#[memory]
#label=swap
#instance=swap
##separator=false
#interval=2
##min_width=swap 99.9%
# Disk usage
#

View file

@ -19,4 +19,4 @@ else color="#66cccc"
fi
# Affichage
printf "<span foreground=\"%s\">%3d%%</span>" "$color" "$used"
printf "cpu<span foreground=\"%s\">%3d%%</span>" "$color" "$used"

View file

@ -50,4 +50,6 @@ else
color15="#F2777A"
fi
printf "<span foreground=\"$color\">%4.4s</span> <span foreground=\"$color5\">%4.4s</span> <span foreground=\"$color15\">%4.4s</span>" ${load} ${load5} ${load15}
printf "load <span foreground=\"$color\">%4.4s</span> <span foreground=\"$color5\">%4.4s</span> <span foreground=\"$color15\">%4.4s</span>" ${load} ${load5} ${load15}
echo
printf "load <span foreground=\"$color\">%4.4s</span>" ${load}

View file

@ -1,5 +1,26 @@
#!/bin/bash
LONG=30
SHORT=15
human_time() {
local seconds="$1"
if [[ "$seconds" -lt 0 ]]
then
echo "--:--"
return
fi
local minutes=$(( $seconds / 60 ))
seconds=$(( $seconds % 60 ))
if [[ "$minutes" -ge 90 ]]
then
printf "%5s\n" "${minutes}m"
else
printf "%02d:%02d\n" "$minutes" "$seconds"
fi
return
}
if ! systemctl --user is-active mpd &>/dev/null
then
origstatus='off'
@ -13,8 +34,6 @@ case $BLOCK_BUTTON in
1) mpc -q prev ;;
2) mpc -q toggle ;;
3) mpc -q next ;;
4) mpc -q seek +5 ;;
5) mpc -q seek -5 ;;
esac
status="<span foreground=\"#6699CC\">"
@ -29,53 +48,87 @@ if [[ "$origstatus" != "stop" ]] && [[ "$origstatus" != "off" ]]
then
if [[ ! -f /dev/shm/mpd ]]
then
mpc -f '[[%artist%, ]%title%|[%file%]' current > /dev/shm/mpd
mpc -f '[[%artist%§]%title%|[%file%]' current > /dev/shm/mpd
fi
song=$(</dev/shm/mpd)
song="${song//&/and}"
if [[ "${#song}" -gt $LONG ]]
then
scrolling=long
elif [[ "${#song}" -gt $SHORT ]]
then
scrolling=short
else
scrolling=none
fi
if [[ "$scrolling" != "none" ]]
then
scroll="$(</dev/shm/mpd-scroll)"
if [[ -z "${scroll// /}" ]]
then
cp /dev/shm/mpd /dev/shm/mpd-scroll
printf "%-${LONG}s" "$(</dev/shm/mpd)" > /dev/shm/mpd-scroll
song="$(</dev/shm/mpd-scroll)"
else
song="$(</dev/shm/mpd-scroll)"
echo "${song:1} " > /dev/shm/mpd-scroll
printf "%-${LONG}s" "${song:1}" > /dev/shm/mpd-scroll
fi
fi
alltime="$(mpc status | column -t -o ' ' | sed -n '2p' | cut -f3)"
elapsed_time="$(dateconv -f "%0H:%0M" "${alltime%/*}" || echo "--:--")"
total_time="$(dateconv -f "%0H:%0M" "${alltime#*/}" || echo "--:--")"
left_time="$(datediff -f "%0H:%0M" "$elapsed_time" "$total_time" || echo "--:--")"
time="$(echo -e 'status\nclose' | nc -U .mpd/socket | grep time \
| cut -d' ' -f2)"
time="[$elapsed_time $left_time $total_time]"
shorttime="$elapsed_time $left_time"
time_elapsed=$(human_time "${time%:*}")
time_total=$(human_time "${time#*:}")
time_left=$(human_time "$(( ${time#*:} - ${time%:*} ))")
if [[ "$time" = "[ ]" ]] || [[ -z "$time" ]]
longtime="[$time_elapsed $time_left ${time_total/00:00/--:--}]"
shorttime="$time_elapsed $time_left"
case $scrolling in
long)
longsong="${song} "
shortsong="${song} "
;;
short)
longsong="$(</dev/shm/mpd) "
shortsong="${song} "
;;
none)
longsong="$(</dev/shm/mpd) "
shortsong="$longsong"
;;
esac
longsong="${longsong:0:$LONG}"
shortsong="${shortsong:0:$SHORT}"
longsong="${longsong//&/&amp;}"
shortsong="${shortsong//&/&amp;}"
if [[ "$longsong" =~ § ]]
then
time="[--:-- --:-- --:--]"
fi
if [[ -z "$shorttime" ]] || [[ "$shorttime" = " " ]]
longsong="<i>${longsong/§/</i> }"
elif [[ "$song" =~ § ]]
then
shorttime="--:-- --:--"
longsong="<i>${longsong}</i>"
fi
if [[ "${#shorttime}" -eq 6 ]]
if [[ "$shortsong" =~ § ]]
then
shorttime="${shorttime}--:--"
shortsong="<i>${shortsong/§/</i> }"
elif [[ "$song" =~ § ]]
then
shortsong="<i>${shortsong}</i>"
fi
echo "${song:0:25} $status$time</span>"
echo "${song:0:10} $status$shorttime</span>"
echo "${longsong} $status$longtime</span>"
echo "${shortsong} $status$shorttime</span>"
else
[[ -f /dev/shm/mpd ]] && rm /dev/shm/mpd
[[ -f /dev/shm/mpd-scroll ]] && rm /dev/shm/mpd-scroll
echo "$status[--:-- --:-- --:--]</span>"
echo "$status--:-- --:--</span>"
printf "%${LONG}s $status[--:-- --:-- --:--]</span>\n" " "
printf "%${SHORT}s $status--:-- --:--</span>\n" " "
fi

View file

@ -5,9 +5,9 @@ export MPD_HOST="$HOME/.mpd/socket"
while true
do
systemctl --user is-active mpd.service || exit 1
infos=$(mpc -w -f '[[%artist% - ]%title%[\n%album%]]|[%file%]' current)
mpc -f '[[%artist%, ]%title%|[%file%]' current > /dev/shm/mpd
cp /dev/shm/mpd /dev/shm/mpd-scroll
infos=$(mpc -w -f '[[%artist%\n]%title%[\n%album%]]|[%file%]' current)
mpc -f '[[%artist%§]%title%|[%file%]' current > /dev/shm/mpd
echo "$(</dev/shm/mpd) " > /dev/shm/mpd-scroll
if [[ -z "$infos" ]]
then
infos="<i>Arrêt</i>"