#!/bin/bash # printVolCont # continuously print alsa master volume as ascii slider ─────│───── ☐ Ξ · ‖ • # to be used with tint2 executor like: #execp_command = printVolCont #execp_continuous = 1 # awk, bc needed # 2017 by bronto, fixed by o9000 (echo ""; stdbuf -oL alsactl monitor) | while read do debug="--true" volPercents=$(awk -F"[^0-9]*" '/dB/ { print $3 }' <(amixer sget Master)) mute=$(awk -F"[][]" '/dB/ { print $6 }' <(amixer sget Master)) if (( volPercents > 100 )); then volPercents=100 fi if (( volPercents < 0 )); then volPercents=0 fi chars="20" fil="─" pos="│" pos=" $volPercents " # Enable this to have a display like ─────50───── # if mute if [ "$mute" == "off" ]; then pos=" ___ " fi [ "$debug" = true ] && { echo "$pos pos" ;} [ "$debug" = true ] && { echo "$volPercents volPercents" ;} faktor=$(echo "scale=2;$chars/100" | bc) vol=$(echo "scale=0;($volPercents*$faktor+0.5)/1" | bc -l) [ "$debug" = true ] && { echo "$vol vol" ;} postloop=$(echo "$chars-$vol" | bc) if (( vol == chars )); then postloop=0 fi preloop=$(echo "$vol-1" | bc) if (( vol == 0 )); then preloop=0 postloop=$(echo "$chars-$vol-1" | bc) fi [ "$debug" = true ] && { echo "$preloop preloop" ;} [ "$debug" = true ] && { echo "$postloop postloop" ;} for i in $(seq 1 $preloop); do printf "%s" "$fil" done printf "%s" "$pos" for i in $(seq 1 $postloop); do printf "%s" "$fil" done printf "\n" done