Skip to content

Instantly share code, notes, and snippets.

@sgnyjohn
Created March 29, 2024 13:56
Show Gist options
  • Save sgnyjohn/bdcec9abd3b791eb813e74fe04ceb308 to your computer and use it in GitHub Desktop.
Save sgnyjohn/bdcec9abd3b791eb813e74fe04ceb308 to your computer and use it in GitHub Desktop.
sh script: conecta/ativa bluetooth - ativa equalizador
#!/bin/bash
# 2024 @sgnyjohn
# conecta bluetooth - ativa equalizador
x=$(bluetoothctl devices|grep -vi "No default")
if [ "$x" = "" ]; then
echo "sem controladores..."
exit
M=bluetooth
lsmod |grep $M|grep -viE ^$M|while read md x; do
echo rmmod $md
rmmod $md
done
rmmod $M
sleep 1
modprobe -v $M
exit
fi
GRN="\[$(tput setaf 2)\]"
RED="\[$(tput setaf 1)\]"
YLL="\[$(tput setaf 3)\]"
BLU="\[$(tput setaf 4)\]"
BLD="$(tput bold)"
RST="$(tput sgr0)"
LF="
"
LANG=C
ng() {
echo -n "$NG$1$RST"
}
setDef() {
echo "set-default-sink $1" | pacmd
}
et() {
echo "================================================================="
}
et1() {
echo "-----------------------------------------------------------------"
}
eq=
onOffEqualiz() {
if [ "$eq" == "enable" ]; then
pactl load-module module-equalizer-sink
else
pactl unload-module module-equalizer-sink
fi
}
addBlue() {
while true; do
local n=1
local o=0
IFS=" "
et
echo "conectar nodo bluetooth"
et1
while read x mac nome; do
echo "$n - $nome ($mac)"
o="$o$LF$n $mac $nome"
let n=n+1
done < <(echo "devices"|bluetoothctl|grep Device)
et1
echo "0 - sair"
et
read op
if [ ".$op" == "." ]; then
continue
elif [ $op -eq 0 ]; then
break;
fi
while read n mac nome; do
if [ $n -eq $op ]; then
echo "connect $mac"|bluetoothctl
# espera conect
n=0
while true; do
if [ "$(pactl list sinks|grep $mac)" != "" ]; then
break
elif [ $n -ge 12 ]; then
echo "=========="
echo "ERRO conex"
echo "=========="
return
fi
echo "... esperando $n conex $mac "
let n=n+1
sleep 2s
done
return
elif [ -$n -eq $op ]; then
echo "disconnect $mac"|bluetoothctl
sleep 1
return
fi
done < <(echo "$o")
done
}
selO() {
while true; do
if [ "$(pactl list sinks|grep -i equaliz)" == "" ]; then
eq="enable"
else
eq="disable"
fi
local n=1
local o=0
local p
local no
df="$(pacmd info|grep -i "Default sink name:"|cut -d: -f 2|xargs)"
o=0
et
echo "selecione audio padrão"
et1
while read ln; do
local x=$(echo $ln|cut -d: -f 1 | xargs)
local p=$(echo $ln|cut -d: -f 2 | xargs)
if [ "$(echo $x|grep Des)" != "" ]; then
if [ "$no" == "$df" ]; then
echo "$n - $BLD$p$LF $no$RST"
else
echo "$n - $p$LF $no"
fi
o="$o$LF$n $no"
let n=n+1
else
no="$p"
fi
done < <(LANG=C pactl list sinks|grep -E "Name:|Description:")
et1
#echo "atual $df"
#et1
echo "8 - $eq equalizer (1 qpaeq / 2 pulseaudio-equalizer-gtk)"
echo "9 - novo bluetooth"
echo "0 - sair"
et
read op
if [ ".$op" == "." ]; then
continue
elif [ $op -eq 81 ]; then
qpaeq &
sleep 3s
continue
elif [ $op -eq 82 ]; then
pulseaudio-equalizer-gtk &
sleep 3s
continue
elif [ $op -eq 8 ]; then
onOffEqualiz
continue
elif [ $op -eq 9 ]; then
addBlue
continue
elif [ $op -eq 0 ]; then
return
fi
while read n p; do
if [ $n -eq $op ]; then
setDef $p
break
fi
done < <(echo "$o")
done
}
selO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment