From 22a270eba9568af1394a46429f1a379200496cf9 Mon Sep 17 00:00:00 2001 From: Amin Bandali Date: Mon, 1 Apr 2024 15:21:11 -0400 Subject: Break pulse volume code out of bar and into its own script In part so that it could easily be used in Emacs as well. Also rename pacify-pulseaudio to b-pacify (as in PAcify). --- .local/bin/b-bar | 13 +++++++++++++ .local/bin/b-pacify | 28 ++++++++++++++++++++++++++++ .local/bin/b-pavols | 23 +++++++++++++++++++++++ .local/bin/my-bar | 20 -------------------- .local/bin/pacify-pulseaudio | 28 ---------------------------- 5 files changed, 64 insertions(+), 48 deletions(-) create mode 100755 .local/bin/b-bar create mode 100755 .local/bin/b-pacify create mode 100755 .local/bin/b-pavols delete mode 100755 .local/bin/my-bar delete mode 100755 .local/bin/pacify-pulseaudio (limited to '.local') diff --git a/.local/bin/b-bar b/.local/bin/b-bar new file mode 100755 index 0000000..e326673 --- /dev/null +++ b/.local/bin/b-bar @@ -0,0 +1,13 @@ +#!/bin/sh +while true +do + b0="/sys/class/power_supply/BAT0" + bat="$(cat $b0/capacity)" + # batl="$(cat $b0/capacity_level)" + vols="$(b-pavols)" + load="$(cat /proc/loadavg | cut -d' ' -f1)" + time="$(date +'%a, %d %b %Y %R %z')" + printf "%s%% | %s | %s | %s\n" \ + "$bat" "$vols" "$load" "$time" + sleep 5 +done diff --git a/.local/bin/b-pacify b/.local/bin/b-pacify new file mode 100755 index 0000000..18d6ee5 --- /dev/null +++ b/.local/bin/b-pacify @@ -0,0 +1,28 @@ +#!/bin/sh + +# Copyright (c) 2024 Amin Bandali +# +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +# pulseaudio is trash and insists on using machine-id as a prefix for +# its database filenames under ~/.config/pulse. So, on systems with +# randomized machine-ids like Devuan GNU/Linux it shits the bed and +# can't find its own database files. So we do its job for it and +# rename its database files on each boot. Ditto for libcanberra's +# event sound cache database. + +cur_id_path=/var/lib/dbus/machine-id +prev_id_path="$XDG_CACHE_HOME/tmp-prevmid" +cur_id="$(cat $cur_id_path)" +prev_id="$(cat $prev_id_path)" + +for f in $XDG_CONFIG_HOME/pulse/$prev_id-* \ + $XDG_CACHE_HOME/event-sound-cache.tdb.$prev_id.*; do + fnew="$(echo $f | sed "s/$prev_id/$cur_id/")" + mv $f $fnew +done + +cp -p $cur_id_path $prev_id_path diff --git a/.local/bin/b-pavols b/.local/bin/b-pavols new file mode 100755 index 0000000..76606e2 --- /dev/null +++ b/.local/bin/b-pavols @@ -0,0 +1,23 @@ +#!/bin/sh + +# default sink (output) +sink_volume="$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n1)" +sink_mute="$(pactl get-sink-mute @DEFAULT_SINK@ | grep -o 'no\|yes')" +# default source (input) +source_volume="$(pactl get-source-volume @DEFAULT_SOURCE@ | grep -Po '\d+(?=%)' | head -n1)" +source_mute="$(pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'no\|yes')" + +if [ "$sink_mute" = "no" ]; then + sink_mute='+' +else + sink_mute='-' +fi + +if [ "$source_mute" = "no" ]; then + source_mute='+' +else + source_mute='-' +fi + +printf "%s%s,%s%s\n" \ + "$sink_volume" "$sink_mute" "$source_volume" "$source_mute" diff --git a/.local/bin/my-bar b/.local/bin/my-bar deleted file mode 100755 index 8a37d2f..0000000 --- a/.local/bin/my-bar +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -while true -do - b0="/sys/class/power_supply/BAT0" - bat="$(cat $b0/capacity)" - # batl="$(cat $b0/capacity_level)" - sinkv="$(pactl get-sink-volume @DEFAULT_SINK@ | grep -Po '\d+(?=%)' | head -n1)" - sinkm="$(pactl get-sink-mute @DEFAULT_SINK@ | grep -o 'no\|yes')" - srcv="$(pactl get-source-volume @DEFAULT_SOURCE@ | grep -Po '\d+(?=%)' | head -n1)" - srcm="$(pactl get-source-mute @DEFAULT_SOURCE@ | grep -o 'no\|yes')" - [ "$sinkm" = "no" ] && sinkm='+' || sinkm='-' - [ "$srcm" = "no" ] && srcm='+' || srcm='-' - load="$(cat /proc/loadavg | cut -d' ' -f1)" - time="$(date +'%a, %d %b %Y %R %z')" - printf "%s%% | %s%s,%s%s | %s | %s\n" \ - "$bat" \ - "$sinkv" "$sinkm" "$srcv" "$srcm" \ - "$load" "$time" - sleep 5 -done diff --git a/.local/bin/pacify-pulseaudio b/.local/bin/pacify-pulseaudio deleted file mode 100755 index 18d6ee5..0000000 --- a/.local/bin/pacify-pulseaudio +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2024 Amin Bandali -# -# Copying and distribution of this file, with or without modification, -# are permitted in any medium without royalty provided the copyright -# notice and this notice are preserved. This file is offered as-is, -# without any warranty. - -# pulseaudio is trash and insists on using machine-id as a prefix for -# its database filenames under ~/.config/pulse. So, on systems with -# randomized machine-ids like Devuan GNU/Linux it shits the bed and -# can't find its own database files. So we do its job for it and -# rename its database files on each boot. Ditto for libcanberra's -# event sound cache database. - -cur_id_path=/var/lib/dbus/machine-id -prev_id_path="$XDG_CACHE_HOME/tmp-prevmid" -cur_id="$(cat $cur_id_path)" -prev_id="$(cat $prev_id_path)" - -for f in $XDG_CONFIG_HOME/pulse/$prev_id-* \ - $XDG_CACHE_HOME/event-sound-cache.tdb.$prev_id.*; do - fnew="$(echo $f | sed "s/$prev_id/$cur_id/")" - mv $f $fnew -done - -cp -p $cur_id_path $prev_id_path -- cgit v1.2.3-60-g2f50