Add sound function keys and clopper-ob-bash command
parent
3d0ca07644
commit
27165fcac3
@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
##
|
||||
# This is the code-clopper-opebox specific bash. It should be used to execute bash
|
||||
# scripts that need some standard functions to be predefined.
|
||||
|
||||
here() {
|
||||
dirname "$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
}
|
||||
|
||||
source "$(here)/../lib/common-functions.bash"
|
||||
|
||||
# Source any script that is passed as parameter and pass it all other arguments.
|
||||
source "$@"
|
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env clopper-ob-bash
|
||||
##
|
||||
# Sound controlls
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
master-percentage() {
|
||||
amixer -D pulse get Master | grep -Pom 1 '(?<=\[)[0-9]+(?=%\])'
|
||||
}
|
||||
|
||||
master-status() {
|
||||
amixer -D pulse get Master | grep -Pom 1 '(?<=\[)(on|off)(?=\]$)'
|
||||
}
|
||||
|
||||
master-is-on() {
|
||||
[[ $(master-status) == 'on' ]]
|
||||
}
|
||||
|
||||
increase-master() {
|
||||
declare master_percentage=''
|
||||
master_percentage="$(master-percentage)"
|
||||
[[ $master_percentage -le 100 ]] || return 1
|
||||
amixer -D pulse set Master $((master_percentage + 8))'%'
|
||||
}
|
||||
|
||||
decrease-master() {
|
||||
declare master_percentage=''
|
||||
master_percentage="$(master-percentage)"
|
||||
[[ $master_percentage -ge 0 ]] || return 1
|
||||
amixer -D pulse set Master $((master_percentage - 8))'%'
|
||||
}
|
||||
|
||||
disable-master() {
|
||||
amixer -D pulse set Master off
|
||||
}
|
||||
|
||||
enable-master() {
|
||||
amixer -D pulse set Master on
|
||||
}
|
||||
|
||||
notify-volume() {
|
||||
notify-send.sh -i "$(icon sound-up)" \
|
||||
--replace-file="$HOME/.cache/clopper-ob/sound.id" \
|
||||
" $(bar $(($(master-percentage)/4)))"
|
||||
play-sound volume-change
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
+)
|
||||
increase-master
|
||||
notify-volume
|
||||
;;
|
||||
-)
|
||||
decrease-master
|
||||
notify-volume
|
||||
;;
|
||||
toggle)
|
||||
if master-is-on; then
|
||||
disable-master
|
||||
notify-send.sh -i "$(icon sound-off)" 'Muted' \
|
||||
--replace-file="$HOME/.cache/clopper-ob/sound.id"
|
||||
else
|
||||
enable-master
|
||||
notify-volume
|
||||
fi
|
||||
;;
|
||||
esac
|
@ -0,0 +1,5 @@
|
||||
##
|
||||
# This file should be sourced when testing scripts locally in the project folder, otherwise
|
||||
# the already installed clopper-ob-bash would be used and libraries wouldn't be refreshed.
|
||||
|
||||
PATH="$(pwd)/bin:$PATH" /bin/bash -i
|
@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
##
|
||||
# Some commonly used functions for clopper-ob
|
||||
|
||||
here() {
|
||||
dirname "$(readlink -f "${BASH_SOURCE[0]}")"
|
||||
}
|
||||
|
||||
bar() {
|
||||
declare -i count="$1"
|
||||
[[ $count -eq 0 ]] && return 0
|
||||
printf '─'
|
||||
((count--))
|
||||
bar "$count"
|
||||
}
|
||||
|
||||
icon() {
|
||||
declare notif_icons='/usr/share/icons/Numix/48/notifications'
|
||||
case "$1" in
|
||||
brightness)
|
||||
echo -n "$notif_icons/notification-display-brightness.svg"
|
||||
;;
|
||||
sound-up)
|
||||
echo -n "$notif_icons/notification-audio-volume-high.svg"
|
||||
;;
|
||||
sound-off)
|
||||
echo -n "$notif_icons/notification-audio-volume-muted.svg"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
play-sound() {
|
||||
declare sound_dir='/usr/share/sounds/freedesktop/stereo'
|
||||
case "$1" in
|
||||
volume-change)
|
||||
ogg123 "$sound_dir/audio-volume-change.oga"
|
||||
;;
|
||||
esac
|
||||
}
|
Loading…
Reference in New Issue