-
Notifications
You must be signed in to change notification settings - Fork 1
/
vol.nu
executable file
·105 lines (96 loc) · 2.31 KB
/
vol.nu
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
#!/bin/env nu
# vol.nu
def get-vol [
--controller (-c): string = "Master" # Controller
] {
amixer sget $controller |
str trim |
split row -r '\n' |
last 2 |
split column -r '[\[\]]' |
select column2 column4 |
rename volume status |
merge ([left right] | wrap index) |
update volume {$in | str trim -c "%" | into int}
}
# Notify current volume
export def notify [
--side (-s): string = "both" # Both, right, left
] {
if not ($side in [both right left]) {
return
}
let side = if ($side == "both") { "right" } else { $side }
let vol = (get-vol | where index == $side)
notify-send $"Volume (($vol.status.0)): ($vol.volume.0)%" -r 45
}
# Set volume
export def set [
value: int # Volume percent
--controller (-c): string = "Master" # Controller
--silent (-s) # Don't notify new values
] {
let output = (amixer set $controller $"($value)%" | complete)
if not $silent {
notify
}
}
# Increment volume
export def inc [
value: int = 5 # Increment value
--controller (-c): string = "Master" # Controller
--side (-s): string = "both" # Both, right, left
] {
if not ($side in [both right left]) {
return
}
let side = if ($side == "both") { "right" } else { $side }
let vol = (get-vol --controller $controller |
where index == $side |
get volume |
first
)
set ($vol + $value) --controller $controller
}
# Decrement volume
export def dec [
value: int = 5 # Increment value
--controller (-c): string = "Master" # Controller
--side (-s): string = "both" # Both, right, left
] {
inc (-1 * $value) --controller $controller --side $side
}
# Mute volume
export def off [
--controller (-c): string = "Master" # Controller
--silent (-s) # Don't notify new values
] {
let output = (amixer sset $controller off | complete)
if not $silent {
notify
}
}
# Turn volume on
export def on [
--controller (-c): string = "Master" # Controller
--silent (-s) # Don't notify new values
] {
let output = (amixer sset $controller on | complete)
if not $silent {
notify
}
}
# Toggle volume
export def toggle [
--controller (-c): string = "Master" # Controller
--silent (-s) # Don't notify new values
] {
let output = (amixer sset $controller toggle | complete)
if not $silent {
notify
}
}
# Get volume
export def main [] {
get-vol
}