btcli


Logs | Files | LICENSE | GitLab


1
commit 493603dbc9146424838dc5e10ee10c429630fe97
2
Author: Connor Etherington <[email protected]>
3
Date:   Sun Dec 18 03:27:52 2022 +0200
4
5
    Auto-Commit Update 18.12.2022 - 03:27:52
6
---
7
 PKGBUILD                                  |   2 +-
8
 usr/bin/btcli                             | 116 ++++++++++++++++++++++++++++++
9
 usr/share/doc/{qbt => btcli}/.gitkeep     |   0
10
 usr/share/licenses/{qbt => btcli}/LICENSE |   2 +-
11
 4 files changed, 118 insertions(+), 2 deletions(-)
12
13
diff --git a/PKGBUILD b/PKGBUILD
14
index d470f9f..84db57f 100644
15
--- a/PKGBUILD
16
+++ b/PKGBUILD
17
@@ -1,6 +1,6 @@
18
 # Maintainer: Connor Etherington <[email protected]>
19
 # ---
20
-pkgname=qbt
21
+pkgname=btcli
22
 pkgver=0.1.0
23
 pkgrel=1
24
 pkgdesc="A simple, easy to use, CLI bluetooth connections manager"
25
diff --git a/usr/bin/btcli b/usr/bin/btcli
26
new file mode 100755
27
index 0000000..eb40150
28
--- /dev/null
29
+++ b/usr/bin/btcli
30
@@ -0,0 +1,116 @@
31
+#!/usr/bin/env bash
32
+
33
+blue(){ echo -e "$(tput bold; tput setaf 6)${*}$(tput sgr0)"; }
34
+msg(){ echo -e "$(tput bold; tput setaf 2)[+] ${*}$(tput sgr0)"; }
35
+err(){ echo "$(tput bold; tput setaf 1)[-] ERROR: ${*}$(tput sgr0)"; }
36
+
37
+btl='bluetoothctl'
38
+sel1=$(mktemp -uq)
39
+sel2=$(mktemp -uq)
40
+devices=$(mktemp -uq)
41
+ids=$(mktemp -uq)
42
+lines=$(mktemp -uq)
43
+all=$(mktemp -uq)
44
+
45
+trap 'rm -f $sel1 $sel2 $devices $ids $lines $all' EXIT
46
+
47
+cat <<-EOF >$sel1
48
+   Scan for Devices
49
+   Connect to Device
50
+   Activate Bluetooth
51
+   Deactivate Bluetooth
52
+EOF
53
+
54
+# Devices:
55
+
56
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//'|cut -d\  -f1)" >> $lines
57
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//'|cut -d\  -f2)" >> $ids
58
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//'|cut -d\  -f3-)" >> $devices
59
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//')" >> $all
60
+
61
+# Main :
62
+
63
+connectfunc(){
64
+  $btl connect $1 && exit 0 ||
65
+  $btl trust $1 &&
66
+  $btl pair $1 &&
67
+  $btl connect $1 && exit 0
68
+}
69
+
70
+activatefunc(){
71
+  $btl power on  >/dev/null 2>&1 && msg "Changing power on succeeded ✔" || err "Changing power on failed ✖"
72
+  $btl discoverable on >/dev/null 2>&1 && msg "Changing discoverable on succeeded ✔" || err "Changing discoverable on failed ✖"
73
+  $btl pairable on >/dev/null 2>&1 && msg "Changing pairable on succeeded ✔" || err "Changing pairable on failed ✖"
74
+  $btl agent on >/dev/null 2>&1 && msg "Changing agent on succeeded ✔"
75
+  $btl default-agent on >/dev/null 2>&1 && msg "Changing default-agent on succeeded ✔"
76
+}
77
+
78
+
79
+sel1func(){
80
+  clear ; echo -e "\n" ;
81
+  pair="$(cat $sel1|fzf \
82
+    --prompt="Select an option:                         " \
83
+    --header=" " \
84
+    --height=12 \
85
+    --margin=10%,30% \
86
+    --layout=reverse \
87
+    --border \
88
+    --color=fg:-1,bg:-1,hl:6,fg+:2,bg+:0,hl+:6 \
89
+    --pointer=▶ \
90
+    --marker=✓ \
91
+    --cycle \
92
+    --reverse \
93
+    --no-info \
94
+    --no-hscroll \
95
+    --no-sort \
96
+    --inline-info \
97
+  )"
98
+
99
+
100
+
101
+clear && echo -e "\n"
102
+case $pair in
103
+  *Device) sel2func ;;
104
+  *Activate*) activatefunc ;;
105
+  *Scan*) clear &&  echo -e "";  msg "Scanning for devices...\n" && $btl scan on ;;
106
+  *Deactivate*) $btl power off && msg "Changing power off succeeded ✔" || err "Changing power off failed ✖" ;;
107
+  *) echo "Not found" ;;
108
+esac ; }
109
+
110
+
111
+
112
+# Devices:
113
+
114
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//'|cut -d\  -f1)" >> $lines
115
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//'|cut -d\  -f2)" >> $ids
116
+echo "$($btl devices|nl|sed 's/\s*//' |sed 's/\s*Device//'|cut -d\  -f3-)" >> $devices
117
+
118
+sel2func(){
119
+
120
+  clear ; echo -e "\n"
121
+
122
+  dev="$(cat $devices|fzf \
123
+    --height=20 \
124
+    --margin=18%,40%,40%,40% \
125
+    --color bg:"#222222",preview-bg:"#333333" \
126
+    --no-extended \
127
+    --layout reverse \
128
+    --header " " \
129
+    --prompt "          Select Device :" \
130
+    --no-info \
131
+    --disabled \
132
+    --border \
133
+    --bold \
134
+    --keep-right)"
135
+
136
+
137
+  while IFS=\   read -r  line id device; do
138
+		n=$((n+1))
139
+		case "$dev" in
140
+      "$device") ! connectfunc $id && err "Failed to connect to $device ✖" || msg "Connected to $device ✔" ;;
141
+    esac
142
+  done < $all
143
+}
144
+
145
+sel1func
146
+
147
diff --git a/usr/share/doc/qbt/.gitkeep b/usr/share/doc/btcli/.gitkeep
148
similarity index 100%
149
rename from usr/share/doc/qbt/.gitkeep
150
rename to usr/share/doc/btcli/.gitkeep
151
diff --git a/usr/share/licenses/qbt/LICENSE b/usr/share/licenses/btcli/LICENSE
152
similarity index 95%
153
rename from usr/share/licenses/qbt/LICENSE
154
rename to usr/share/licenses/btcli/LICENSE
155
index 276f429..2581502 100644
156
--- a/usr/share/licenses/qbt/LICENSE
157
+++ b/usr/share/licenses/btcli/LICENSE
158
@@ -1,7 +1,7 @@
159
 MIT/X Consortium License
160
 
161
 Creator /Maintainer :
162
-© 2020-2022 Connor Etherington <[email protected]>
163
+© 2022-present Connor Etherington <[email protected]>
164
 ---------------------------------------------------------------------------
165
 Contributors:
166