-
-
Save kanna5/c12c3fb28322618b0548c9004e0aa1ac to your computer and use it in GitHub Desktop.
Easy volume control in the console. Works with PulseAudio and PipeWire with pipewire-pulse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
mute() { | |
pamixer --mute | |
} | |
unmute() { | |
pamixer --unmute | |
} | |
is_muted() { | |
pamixer --get-mute | grep -q true | |
} | |
get_default_sink() { | |
pamixer --get-default-sink | tail -n+2 | |
} | |
get_volume() { | |
pamixer --get-volume | |
} | |
set_volume_safe() { | |
pamixer --set-volume "$1" --set-limit 30 | |
} | |
set_volume() { | |
pamixer --set-volume "$1" | |
} | |
if ! command -v pamixer > /dev/null; then | |
echo '"pamixer" not installed' # https://github.com/cdemoulins/pamixer | |
exit 1 | |
fi | |
RESET="\033[0m" | |
BOLD="\033[1m" | |
BLUE="\033[34m" | |
RED="\033[31m" | |
CYAN="\033[36m" | |
show_default_sink() { | |
echo -e "${BOLD}Default sink: ${RESET}${BLUE}$(get_default_sink)${RESET}" | |
} | |
show_volume() { | |
echo -ne "${BOLD}Volume: ${RESET}${CYAN}$(get_volume)%${RESET}" | |
is_muted && echo -ne "${RED} (Muted)${RESET}" | |
echo | |
} | |
case $1 in | |
m|mu|mut|mute) | |
mute | |
show_volume | |
;; | |
u|un|unm|unmu|unmut|unmute) | |
unmute | |
show_volume | |
;; | |
[0-9]|[0-9][0-9]|100) | |
set_volume_safe "$1" | |
show_volume | |
;; | |
[0-9]!|[0-9][0-9]!|100!) | |
set_volume "${1%!}" | |
show_volume | |
;; | |
.) | |
show_default_sink | |
show_volume | |
;; | |
*) | |
echo "Usage: $0 <volume>[!]|m[ute]|u[nmute]|." | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment