diff options
author | Biswakalyan Bhuyan <biswa@surgot.in> | 2022-02-26 20:31:12 +0530 |
---|---|---|
committer | Biswakalyan Bhuyan <biswa@surgot.in> | 2022-02-26 20:31:12 +0530 |
commit | 85ae438fbc238fe56bcb1c10a12ec52365053cb6 (patch) | |
tree | 7aa2c802739657f22fd8de735207b27fc6e7e8a9 /modules/volumebar | |
download | dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.tar.gz dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.tar.bz2 dwmbar-85ae438fbc238fe56bcb1c10a12ec52365053cb6.zip |
dwmbar dotfiles
Diffstat (limited to 'modules/volumebar')
-rwxr-xr-x | modules/volumebar | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/volumebar b/modules/volumebar new file mode 100755 index 0000000..219428d --- /dev/null +++ b/modules/volumebar @@ -0,0 +1,40 @@ +#!/bin/bash + +# Prints out the volume percentage + +# Dependencies: bc + +VOLUME_WIDTH=9 +VOLUME_SLIDER='⬤' +VOLUME_RAIL='◯' +VOLUME_MUTED='muted' + +PREFIX='' + +# If volume is >100 +ALERT='!!!' + +get_volume(){ + active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}') + curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}') + volume=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ') + slider_position=$(python -c "print(($volume / 100) * $VOLUME_WIDTH)") + + if [ "${curStatus}" = 'yes' ] + then + echo "$VOLUME_MUTED" + exit 0 + else + for i in $(seq 1 $VOLUME_WIDTH); do + [[ $i = $slider_position ]] && BAR=$BAR$VOLUME_SLIDER + [[ $i < $slider_position ]] && BAR=$BAR$VOLUME_SLIDER + [[ $i > $slider_position ]] && BAR=$BAR$VOLUME_RAIL + done + fi + + [[ $volume -gt 100 ]] && PREFIX=$PREFIX$ALERT + + echo "$PREFIX$BAR" +} + +get_volume |