-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent-volume.sh
More file actions
126 lines (94 loc) · 3.05 KB
/
Copy pathcurrent-volume.sh
File metadata and controls
126 lines (94 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# current-volume
# Version: 0.1.1
# Author: KeyofBlueS
# Repository: https://github.com/KeyofBlueS/current-volume
# License: GNU General Public License v3.0, https://opensource.org/licenses/GPL-3.0
function show_volume() {
if [[ -n "${SteamEnv}" ]]; then
srlc_cmd=(steam-runtime-launch-client --alongside-steam --host -- /usr/bin/)
fi
wpctl_out="$("${srlc_cmd[@]}wpctl" get-volume "${device}")" || {
echo 'ERROR' >&2
exit 1
}
set -- ${wpctl_out}
vol_float="${2}"
vol_percent="${vol_float#0}"
vol_percent="${vol_percent/.}"
vol_percent="${vol_percent#0}"
if [[ "${wpctl_out}" == *MUTED* ]]; then
echo "${vol_percent}% (MUTE)"
else
echo "${vol_percent}%"
fi
}
function givemehelp() {
current_volume_name="$(readlink -f "${0}")"
echo "
# current-volume
# Version: 0.1.1
# Author: KeyofBlueS
# Repository: https://github.com/KeyofBlueS/current-volume
# License: GNU General Public License v3.0, https://opensource.org/licenses/GPL-3.0
### DESCRIPTION
A tiny, lightweight and fast Bash script to show your system's audio volume.
I mainly wrote this to show the volume in MangoHud, but you can use it anywhere you like, for example in Conky.
### FEATURES
- Uses wpctl (PipeWire) to get the default audio sink/source volume.
- Compatible with Steam runtime environments - automatically wraps wpctl command in steam-runtime-launch-client if SteamEnv is set.
- Shows volume as a simple percentage, e.g., 5%, 60% or 150%.
- Adds (MUTE) if the audio is muted.
### USAGE
$ current-volume <option>
Options:
-s, --sink Show the default sink (e.g. speakers, headphones) volume (default).
-m, --mic Show the default source (e.g. microphone) volume.
-h, --help Show this help.
### USING WITH MangoHud
You can display the current volume in MangoHud by adding a custom command to your MangoHud configuration file (usually ~/.config/mangohud/MangoHud.conf):
custom_text=Volume
exec=${current_volume_name}
custom_text=Mic
exec=${current_volume_name} -m
custom_text is the label that will appear in the overlay.
exec should point to the path where you saved the current-volume.sh script.
The script will automatically detect if you're running in Steam (\$SteamEnv) and display the correct volume with (MUTE) if muted.
This makes it easy to see your system volume directly in games.
"
}
device='@DEFAULT_AUDIO_SINK@'
for opt in "$@"; do
shift
case "$opt" in
'--sink') set -- "$@" '-s' ;;
'--mic') set -- "$@" '-m' ;;
'--help') set -- "$@" '-h' ;;
*) set -- "$@" "$opt"
esac
done
while getopts "smh" opt; do
case ${opt} in
s )
if [[ "${device_set}" -eq '1' ]]; then
echo -e "\e[1;31m## ERROR: -m and -s cannot be used together\e[0m"
exit 1
fi
device='@DEFAULT_AUDIO_SINK@'
device_set=1
;;
m )
if [[ "${device_set}" -eq '1' ]]; then
echo -e "\e[1;31m## ERROR: -s and -m cannot be used together\e[0m"
exit 1
fi
device='@DEFAULT_AUDIO_SOURCE@'
device_set=1
;;
h ) givemehelp; exit 0
;;
*) echo -e "\e[1;31m## ERROR\e[0m"; givemehelp; exit 1
esac
done
show_volume
exit 0