pa: Add sh version

Add POSIX compliant sh version of the pa script.
This commit is contained in:
coderkun 2021-09-12 20:58:32 +02:00
parent 68319d2b55
commit 71bea304af
2 changed files with 37 additions and 3 deletions

12
pa.bash
View File

@ -10,13 +10,19 @@ function profile {
# If either i3s button is 1 or the first argument is “switch”, switch profile
if [[ $BLOCK_BUTTON -eq 1 ]] || [ "$1" == "switch" ] ; then
profile
if ! [ "$CURRENT_PROFILE" = "iec958-stereo-output" ] ; then
if ! [[ "$CURRENT_PROFILE" == *"iec958"* ]] ; then
pacmd set-card-profile 0 output:iec958-stereo
else
pacmd set-card-profile 0 output:hdmi-stereo-extra2
pacmd set-card-profile 0 output:hdmi-stereo
fi
fi
# Print out current profile
profile
echo "${CURRENT_PROFILE%%-*}"
if [[ "$CURRENT_PROFILE" == *"iec958"* ]] ; then
echo "digital"
elif [[ "$CURRENT_PROFILE" == *"hdmi"* ]] ; then
echo "hdmi"
else
echo "${CURRENT_PROFILE%%-*}"
fi

28
pa.sh Executable file
View File

@ -0,0 +1,28 @@
#!/bin/sh
# Detect current profile
profile() {
CURRENT_PROFILE=$(LC_ALL=C pactl list sinks | grep -i "active port" | cut -d " " -f 3)
}
# If either i3s button is 1 or the first argument is “switch”, switch profile
if [[ $BLOCK_BUTTON -eq 1 ]] || [ "$1" == "switch" ] ; then
profile
if ! [[ "$CURRENT_PROFILE" == *"iec958"* ]] ; then
pacmd set-card-profile 0 output:iec958-stereo
else
pacmd set-card-profile 0 output:hdmi-stereo
fi
fi
# Print out current profile
profile
if [[ "$CURRENT_PROFILE" == *"iec958"* ]] ; then
echo "digital"
elif [[ "$CURRENT_PROFILE" == *"hdmi"* ]] ; then
echo "hdmi"
else
echo "${CURRENT_PROFILE%%-*}"
fi