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 bindsym XF86AudioMicMute exec --no-startup-id BLOCK_BUTTON=2 BLOCK_INSTANCE=Capture ${HOME}/.i3blocks/volume && pkill -RTMIN+10 i3blocks
# Media controls # Media controls
bindsym XF86AudioNext exec --no-startup-id mocp -f bindsym XF86AudioNext exec --no-startup-id mpc next
bindsym XF86AudioPrev exec --no-startup-id mocp -r bindsym XF86AudioPrev exec --no-startup-id mpc prev
bindsym XF86AudioPlay exec --no-startup-id mocp -G bindsym XF86AudioPlay exec --no-startup-id mpc toggle
bindsym XF86AudioStop exec --no-startup-id mocp -s bindsym XF86AudioStop exec --no-startup-id mocp stop
# LEDs controls # LEDs controls

View file

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

View file

@ -19,4 +19,4 @@ else color="#66cccc"
fi fi
# Affichage # 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" color15="#F2777A"
fi 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 #!/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 if ! systemctl --user is-active mpd &>/dev/null
then then
origstatus='off' origstatus='off'
@ -13,8 +34,6 @@ case $BLOCK_BUTTON in
1) mpc -q prev ;; 1) mpc -q prev ;;
2) mpc -q toggle ;; 2) mpc -q toggle ;;
3) mpc -q next ;; 3) mpc -q next ;;
4) mpc -q seek +5 ;;
5) mpc -q seek -5 ;;
esac esac
status="<span foreground=\"#6699CC\">" status="<span foreground=\"#6699CC\">"
@ -29,53 +48,87 @@ if [[ "$origstatus" != "stop" ]] && [[ "$origstatus" != "off" ]]
then then
if [[ ! -f /dev/shm/mpd ]] if [[ ! -f /dev/shm/mpd ]]
then then
mpc -f '[[%artist%, ]%title%|[%file%]' current > /dev/shm/mpd mpc -f '[[%artist%§]%title%|[%file%]' current > /dev/shm/mpd
fi fi
song=$(</dev/shm/mpd) 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)" scroll="$(</dev/shm/mpd-scroll)"
if [[ -z "${scroll// /}" ]] if [[ -z "${scroll// /}" ]]
then 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 else
song="$(</dev/shm/mpd-scroll)" song="$(</dev/shm/mpd-scroll)"
echo "${song:1} " > /dev/shm/mpd-scroll printf "%-${LONG}s" "${song:1}" > /dev/shm/mpd-scroll
fi
fi fi
alltime="$(mpc status | column -t -o ' ' | sed -n '2p' | cut -f3)" time="$(echo -e 'status\nclose' | nc -U .mpd/socket | grep time \
elapsed_time="$(dateconv -f "%0H:%0M" "${alltime%/*}" || echo "--:--")" | cut -d' ' -f2)"
total_time="$(dateconv -f "%0H:%0M" "${alltime#*/}" || echo "--:--")"
left_time="$(datediff -f "%0H:%0M" "$elapsed_time" "$total_time" || echo "--:--")"
time="[$elapsed_time $left_time $total_time]" time_elapsed=$(human_time "${time%:*}")
shorttime="$elapsed_time $left_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 then
time="[--:-- --:-- --:--]" longsong="<i>${longsong/§/</i> }"
fi elif [[ "$song" =~ § ]]
if [[ -z "$shorttime" ]] || [[ "$shorttime" = " " ]]
then then
shorttime="--:-- --:--" longsong="<i>${longsong}</i>"
fi fi
if [[ "$shortsong" =~ § ]]
if [[ "${#shorttime}" -eq 6 ]]
then then
shorttime="${shorttime}--:--" shortsong="<i>${shortsong/§/</i> }"
elif [[ "$song" =~ § ]]
then
shortsong="<i>${shortsong}</i>"
fi fi
echo "${song:0:25} $status$time</span>" echo "${longsong} $status$longtime</span>"
echo "${song:0:10} $status$shorttime</span>" echo "${shortsong} $status$shorttime</span>"
else else
[[ -f /dev/shm/mpd ]] && rm /dev/shm/mpd [[ -f /dev/shm/mpd ]] && rm /dev/shm/mpd
[[ -f /dev/shm/mpd-scroll ]] && rm /dev/shm/mpd-scroll [[ -f /dev/shm/mpd-scroll ]] && rm /dev/shm/mpd-scroll
echo "$status[--:-- --:-- --:--]</span>" printf "%${LONG}s $status[--:-- --:-- --:--]</span>\n" " "
echo "$status--:-- --:--</span>" printf "%${SHORT}s $status--:-- --:--</span>\n" " "
fi fi

View file

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