-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvol
executable file
·105 lines (89 loc) · 2.48 KB
/
vol
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
#!/usr/bin/env fish
# vol - change system volume.
# more convenient and intuitive than typing crap like "amixer -c 2 set PCM +2%"
# used as a reference:
# https://github.com/claudius-kienle/polybar-pipewire-control/blob/master/pipewire-control.bash
# perhaps in the future pw-volume could be used (it failed to compile for me before)
# usage:
# vol <operation> <parameter>
# or:
# vol <operation and parameter>
# operations are:
# + u up - increase volume.
# - d down - decrease volume.
# r reset s set - set volume to the specified value.
# [number]% - set volume to the specified value.
# t toggle - toggle muting.
# m mute - mute.
# un unmute - unmute.
# switch swap output o - switch output device (basically just unmutes one and mutes the others).
# examples:
#
# show current volume:
# vol
#
# decrease volume by 2%:
# vol d
#
# increase volume by 5%:
# vol 5+
#
# increase volume by 3%:
# vol u 3
#
# toggle muting:
# vol t
#
# set volume to 40%:
# vol 40
# settings:
set increment 4
# code:
function default_sink_name
string match 'Default Sink:*' (pactl info) | string sub -s 15
end
function sink_id
pactl list sinks short | string match "$argv"
end
function sink_description
string match --regex '\n*Description:.*' "$pactl" | string sub -s 14
end
function sink_volume_percent
string match --regex 'Volume:.*?([0-9]+%)' (pactl get-sink-volume "@DEFAULT_SINK@") | tail -1
end
function sink_muted -d "Get whether the default sink is muted. Returns 0 if it's muted and 1 if unmuted."
test 'yes' = "$(string match --regex 'Mute: (.+)' (pactl get-sink-mute '@DEFAULT_SINK@') | tail -1)"
end
function mute
pactl set-sink-mute '@DEFAULT_SINK@' $argv
end
function volume
pactl set-sink-volume '@DEFAULT_SINK@' $argv
end
if test (count $argv) -gt 0
set arg "$argv[1]"
switch "$arg"
case mute m
mute on
case unmute un
mute off
case toggle t
mute toggle
case + u up
volume "+$increment%"
case - d down
volume "-$increment%"
case reset r set s
volume "$argv[2]"
case '*%'
volume "$arg"
case '*'
if string match --quiet --regex '^[0-9]+$' "$arg"; and test "$arg" -gt 0; and test "$arg" -lt 151
volume "$arg%"
else
echo 'vol: error: unrecognized argument'
exit 1
end
end
end
printf '%s%s\n' (sink_volume_percent) (if sink_muted; echo -n ' (muted)'; end)