aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/i3blocks/volume
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/i3blocks/volume')
-rwxr-xr-xscripts/i3blocks/volume37
1 files changed, 25 insertions, 12 deletions
diff --git a/scripts/i3blocks/volume b/scripts/i3blocks/volume
index a55db88..3b2a7f4 100755
--- a/scripts/i3blocks/volume
+++ b/scripts/i3blocks/volume
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
@@ -18,26 +18,37 @@
#------------------------------------------------------------------------
# The second parameter overrides the mixer selection
-# For PulseAudio users, use "pulse"
+# For PulseAudio users, eventually use "pulse"
# For Jack/Jack2 users, use "jackplug"
# For ALSA users, you may use "default" for your primary card
# or you may use hw:# where # is the number of the card desired
-MIXER="default"
-[ -n "$(lsmod | grep pulse)" ] && MIXER="pulse"
-[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
-MIXER="${2:-$MIXER}"
+if [[ -z "$MIXER" ]] ; then
+ MIXER="default"
+ if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then
+ # pulseaudio is running, but not all installations use "pulse"
+ if amixer -D pulse info >/dev/null 2>&1 ; then
+ MIXER="pulse"
+ fi
+ fi
+ [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
+ MIXER="${2:-$MIXER}"
+fi
# The instance option sets the control to report and configure
# This defaults to the first control of your selected mixer
# For a list of the available, use `amixer -D $Your_Mixer scontrols`
-SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
- sed -n "s/Simple mixer control '\([A-Za-z ]*\)',0/\1/p" |
- head -n1
- )}"
+if [[ -z "$SCONTROL" ]] ; then
+ SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
+ sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" |
+ head -n1
+ )}"
+fi
# The first parameter sets the step to change the volume by (and units to display)
# This may be in in % or dB (eg. 5% or 3dB)
-STEP="${1:-5%}"
+if [[ -z "$STEP" ]] ; then
+ STEP="${1:-5%}"
+fi
#------------------------------------------------------------------------
@@ -51,12 +62,14 @@ volume() {
}
format() {
+
perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
# If dB was selected, print that instead
perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
perl_filter+='"; exit}'
- perl -ne "$perl_filter"
+ output=$(perl -ne "$perl_filter")
+ echo "$LABEL$output"
}
#------------------------------------------------------------------------