From: Dmitry Fedotov Date: Fri, 5 Mar 2021 07:24:22 +0000 (+0300) Subject: Add volume control script. X-Git-Url: https://git.dmfe.net/?a=commitdiff_plain;h=81cfd3da96c91aa5f231230d9de1d84610094d66;p=dotfiles Add volume control script. --- diff --git a/config/i3blocks/config b/config/i3blocks/config index 52afcb6..9e0a97e 100644 --- a/config/i3blocks/config +++ b/config/i3blocks/config @@ -60,7 +60,8 @@ command=echo  | ~/scripts/i3b-formatter.sh -s interval=once [volume] -command=~/scripts/volume.sh | ~/scripts/i3b-formatter.sh -r +command=~/scripts/sound/volume.sh | ~/scripts/i3b-formatter.sh -r +signal=10 interval=once min_width=xxx100% diff --git a/config/sxhkd/sxhkdrc b/config/sxhkd/sxhkdrc index 661903a..4643fdd 100644 --- a/config/sxhkd/sxhkdrc +++ b/config/sxhkd/sxhkdrc @@ -1,34 +1,46 @@ # Basic binds super + Return - $TERMINAL -e /bin/bash --rcfile ~/.bash_profile + $TERMINAL -e /bin/bash --rcfile ~/.bash_profile super + m - $TERMINAL -e ncmpcpp + $TERMINAL -e ncmpcpp super + shift + f - $TERMINAL -e ranger + $TERMINAL -e ranger super + shift + t - $TERMINAL -e htop + $TERMINAL -e htop super + c - "${TERMINAL}" -e calc + "${TERMINAL}" -e calc super + shift + n - nohup "${TERMINAL}" -e sh -c 'neofetch;read' >/dev/null & + nohup "${TERMINAL}" -e sh -c 'neofetch;read' >/dev/null & super + Print - import jpg:- | xclip -selection clipboard -t image/jpeg + import jpg:- | xclip -selection clipboard -t image/jpeg super + t - ${SCRIPTS}/shutdown.sh + ${SCRIPTS}/shutdown.sh super + d - ${SCRIPTS}/dmenu-run.sh + ${SCRIPTS}/dmenu-run.sh super + e - ${SCRIPTS}/dmenu-unicode.sh + ${SCRIPTS}/dmenu-unicode.sh super + shift + m - ${SCRIPTS}/dmenumount.sh + ${SCRIPTS}/dmenumount.sh super + shift + x - ${SCRIPTS}/screen-locker.sh + ${SCRIPTS}/screen-locker.sh super + shift + p ${SCRIPTS}/dmenu-pass.sh +# Sound +super + F10 + vc toggle +super + F12 + vc up +super + F11 + vc down +super + shift + F12 + vc up 20 +super + shift + F11 + vc down 20 + super + alt + l - pkill -SIGUSR1 sxhkd + pkill -SIGUSR1 sxhkd shift + ctrl + k - pkill -SIGRTMIN+5 i3blocks + pkill -SIGRTMIN+5 i3blocks diff --git a/scripts/sound/vc b/scripts/sound/vc new file mode 100755 index 0000000..1ccc455 --- /dev/null +++ b/scripts/sound/vc @@ -0,0 +1,30 @@ +#!/bin/sh + +set -e +#set -x + +NUM="${2:-5}" + +PULSE=true + +if [[ ${PULSE} = true ]]; then + toggle() { pulsemixer --toggle-mute ;} + mute() { pulsemixer --mute ;} + up() { pulsemixer --change-volume +"$NUM" ;} + down() { pulsemixer --change-volume -"$NUM" ;} +else + toggle() { amixer sset Master toggle ;} + mute() { amixer sset Master mute ;} + up() { amixer sset Master "$NUM"%+ ;} + down() { amixer sset Master "$NUM"%- ;} +fi + +case "$1" in + toggle) toggle ;; + mute) mute ;; + up) up ;; + down) down ;; +esac >/dev/null + +pkill -RTMIN+10 i3blocks + diff --git a/scripts/sound/volume.sh b/scripts/sound/volume.sh new file mode 100755 index 0000000..e646f15 --- /dev/null +++ b/scripts/sound/volume.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +sink=$( pactl list short sinks | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,' | tail -n 1 ) + +case ${BLOCK_BUTTON} in + 2) + nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null & + ;; + 3) + pactl set-sink-mute $sink toggle + ;; + 4) + pactl set-sink-volume $sink +5% + ;; + 5) + pactl set-sink-volume $sink -5% + ;; +esac + +muted=$( awk '/muted/ {print $2}' <(pacmd list-sinks | grep '^[[:space:]]muted:' | head -n $(( $sink + 1 )) | tail -n 1 ) ) + +if [ "$muted" = "yes" ]; then + icon="" + printf "%s\n" "$icon" +else + vol=$( pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $sink + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) + if [ "$vol" -gt 60 ]; then + icon="" + elif [[ "$vol" -le 60 && "$vol" -gt 30 ]]; then + icon="" + else + icon="" + fi + + printf "%s %s%%\n" "$icon" "$vol" +fi diff --git a/scripts/volume.sh b/scripts/volume.sh deleted file mode 100755 index e646f15..0000000 --- a/scripts/volume.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -sink=$( pactl list short sinks | sed -e 's,^\([0-9][0-9]*\)[^0-9].*,\1,' | tail -n 1 ) - -case ${BLOCK_BUTTON} in - 2) - nohup "${TERMINAL}" -e "${EDITOR}" "$0" >/dev/null & - ;; - 3) - pactl set-sink-mute $sink toggle - ;; - 4) - pactl set-sink-volume $sink +5% - ;; - 5) - pactl set-sink-volume $sink -5% - ;; -esac - -muted=$( awk '/muted/ {print $2}' <(pacmd list-sinks | grep '^[[:space:]]muted:' | head -n $(( $sink + 1 )) | tail -n 1 ) ) - -if [ "$muted" = "yes" ]; then - icon="" - printf "%s\n" "$icon" -else - vol=$( pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $sink + 1 )) | tail -n 1 | sed -e 's,.* \([0-9][0-9]*\)%.*,\1,' ) - if [ "$vol" -gt 60 ]; then - icon="" - elif [[ "$vol" -le 60 && "$vol" -gt 30 ]]; then - icon="" - else - icon="" - fi - - printf "%s %s%%\n" "$icon" "$vol" -fi