-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbt
executable file
·84 lines (68 loc) · 1.64 KB
/
bt
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
#!/usr/bin/env fish
#
# Swap Bluetooth headset profiles
#
# Based a bit on:
# https://askubuntu.com/a/1009156
function reset
rfkill block bluetooth
sleep 0.1
rfkill unblock bluetooth
end
function speak
echo 'Switching to HSP/HFP profile...'
set_profile headset_head_unit
sleep 0.1
set_sink
set_source
end
function listen
echo 'Switching to A2DP profile...'
set_profile a2dp_sink
sleep 0.1
set_sink
end
function toggle
if pacmd list-cards | grep 'A2DP' | grep 'available: yes' 2>&1 > /dev/null
speak
else if pacmd list-cards | grep 'HSP/HFP' | grep 'available: yes' 2>&1 > /dev/null
listen
else
echo 'No Bluetooth profiles found.'
exit 1
end
end
function get_card
pacmd list-cards | grep 'bluez_card' | cut --characters=9- | head --bytes -2
end
function set_sink
set --local sink (pacmd list-sinks | grep 'bluez_sink' | cut --characters=9- | head --bytes -2)
pacmd set-default-sink "$sink"
for i in (pacmd list-sink-inputs | grep 'index' | cut --characters=12-)
pacmd move-sink-input "$i" "$sink"
end
end
function set_source
set --local source (pacmd list-sources | grep --only-matching 'bluez_source\..*\.headset_head_unit')
pacmd set-default-source "$source"
for i in (pacmd list-source-outputs | grep 'index' | cut --characters=12-)
pacmd move-source-output "$i" "$source" 2> /dev/null
end
end
function set_profile --argument-names profile
pacmd set-card-profile (get_card) $profile 2> /dev/null
end
if test (count $argv) -lt 1
toggle
else
switch $argv[1]
case reset
reset
case speak
speak
case listen
listen
case toggle '*'
toggle
end
end