-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluetooth
executable file
·129 lines (115 loc) · 4.94 KB
/
bluetooth
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
127
128
129
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/bluetooth
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/bluetooth
## https://davoudarsalani.ir
source "$HOME"/main/scripts/gb
source "$HOME"/main/scripts/gb-fir-blu-batt
title="${0##*/}"
function update_bluetooth {
"$HOME"/main/scripts/awesome-widgets bluetooth
}
function get_mac {
mac="$(get_input 'device mac address')"
}
heading "$title"
main_items=( 'status' 'blueman-manager' 'blueman-applet' 'turn on' 'turn off' 'controllers' 'controller information' 'select default controller' 'available/paired devices' 'device information' 'set pairable on/off' 'set discoverable on/off' 'pair with a device' 'trust/untrust a device' 'block/unblock a device' 'remove a device' 'connect/disconnect a device' 'configuration path' 'quit program' 'disable auto turning on' 'enable' 'disable' )
main_item="$(pipe_to_fzf "${main_items[@]}")" && wrap_fzf_choice "$main_item" || exit 37
case "$main_item" in
status )
if [ "$bluetooth_status" == 'yes' ]; then
printf 'Bluetooth is off\n' && update_bluetooth && accomplished
else
printf 'Bluetooth is on\n' && update_bluetooth && accomplished
fi ;;
blueman-manager )
blueman-manager 1>/dev/null &
sleep 2
update_bluetooth && accomplished ;;
blueman-applet )
blueman-applet 1>/dev/null 2>&1 &
sleep 2
update_bluetooth && accomplished ;;
'turn on' )
sudo rfkill unblock bluetooth && update_bluetooth && accomplished ;;
'turn off' )
sudo rfkill block bluetooth && update_bluetooth && accomplished ;;
'available controllers' )
bluetoothctl list && accomplished ;;
'controller information' )
bluetoothctl show "$def_ctrlr_mac" && accomplished ;;
'select default controller' )
mac="$(get_input 'mac address [!! or name]')"
bluetoothctl select "$mac" && accomplished ;;
'available/paired devices' )
printf 'available:\t%s\n' "$(bluetoothctl devices)"
printf 'paired:\t\t%s\n' "$(bluetoothctl paired-devices)" && accomplished ;;
'device information' )
get_mac
bluetoothctl info "$mac" && accomplished ;;
'set pairable on/off' )
set_pairable_item="$(pipe_to_fzf 'on' 'off')" && wrap_fzf_choice "$set_pairable_item" || exit 37
case "$set_pairable_item" in
on )
bluetoothctl pairable on && accomplished ;;
off )
bluetoothctl pairable off && accomplished ;;
esac ;;
'set discoverable on/off' )
set_discoverable_item="$(pipe_to_fzf 'on' 'off')" && wrap_fzf_choice "$set_discoverable_item" || exit 37
case "$set_discoverable_item" in
on )
bluetoothctl discoverable on && accomplished ;;
off )
bluetoothctl discoverable off && accomplished ;;
esac ;;
'pair with a device' )
get_mac
bluetoothctl pair "$mac" && accomplished ;;
'trust/untrust a device' )
trust_item="$(pipe_to_fzf 'trust' 'nuntrust')" && wrap_fzf_choice "$trust_item" || exit 37
case "$trust_item" in
trust )
get_mac
bluetoothctl trust "$mac" && accomplished ;;
untrust )
get_mac
bluetoothctl untrust "$mac" && accomplished ;;
esac ;;
'block/unblock a device' )
block_item="$(pipe_to_fzf 'block' 'unblock')" && wrap_fzf_choice "$block_item" || exit 37
case "$block_item" in
block )
get_mac
bluetoothctl block "$mac" && accomplished ;;
unblock )
get_mac
bluetoothctl unblock "$mac" && accomplished ;;
esac ;;
'remove a device' )
get_mac
bluetoothctl remove "$mac" && accomplished ;;
'connect/disconnect a device' )
connect_item="$(pipe_to_fzf 'connect' 'disconnect')" && wrap_fzf_choice "$connect_item" || exit 37
case "$connect_item" in
connect )
get_mac
bluetoothctl connect "$mac" && accomplished ;;
disconnect )
get_mac
bluetoothctl connect "$mac" && accomplished ;;
esac ;;
'configuration path' )
printf '/etc/bluetooth/main.conf\n' && accomplished ;;
'quit program' )
bluetoothctl quit && accomplished ;;
'disable auto turning on' )
gsettings set org.blueman.plugins.powermanager auto-power-on false && accomplished ;;
enable )
sudo systemctl enable bluetooth && accomplished ;;
disable )
sudo systemctl disable bluetooth && accomplished ;;
esac
## The default group the user must be a member of is lp. You can change it here: sudo "$editor" /etc/dbus-1/system.d/bluetooth.conf
## (https://wiki.archlinux.org/index.php/bluetooth)