updated dropdowncalc to use python instead of bc
modified: .local/bin/bt modified: .local/bin/dropdowncalc
This commit is contained in:
parent
939781b342
commit
a47c98fb0c
@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
SCAN_PERIOD=5
|
SCAN_PERIOD=5
|
||||||
AUTOTRUST=false
|
AUTOTRUST=false #trust every newly paired device
|
||||||
AUTOSCAN=true #immediately start scanning when started to speed up pairing process
|
AUTOSCAN=true #immediately start scanning when started to speed up pairing process
|
||||||
#locations of blacklist and hard coded list of paired devices (watch out, need to modify Makefile as well if you want to change these values and still use make install)
|
#locations of blacklist and hard coded list of paired devices (watch out, need to modify Makefile as well if you want to change these values and still use make install)
|
||||||
BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist
|
BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist
|
||||||
@ -25,10 +25,11 @@ power(){
|
|||||||
[ "$powerstatus" = "no" ] && [ "$1" = on ] && bluetoothctl power on
|
[ "$powerstatus" = "no" ] && [ "$1" = on ] && bluetoothctl power on
|
||||||
[ "$powerstatus" = "yes" ] && [ "$1" = off ] && bluetoothctl power off
|
[ "$powerstatus" = "yes" ] && [ "$1" = off ] && bluetoothctl power off
|
||||||
}
|
}
|
||||||
|
|
||||||
scan(){
|
scan(){
|
||||||
scanstatus="$( bluetoothctl show | grep Discovering | awk '{print $2}' )"
|
scanstatus="$( bluetoothctl show | grep Discovering | awk '{print $2}' )"
|
||||||
if [ "$1" = on ]; then
|
if [ "$1" = on ]; then
|
||||||
#sets variable in case scanning was already on before the start of bt
|
#sets variable in case scanning was no already on before the start of bt
|
||||||
[ "$start_scan" = "" ] && start_scan="$( date +'%s' )"
|
[ "$start_scan" = "" ] && start_scan="$( date +'%s' )"
|
||||||
if [ "$scanstatus" = "no" ]; then
|
if [ "$scanstatus" = "no" ]; then
|
||||||
bluetoothctl scan on &
|
bluetoothctl scan on &
|
||||||
@ -61,7 +62,9 @@ startup(){
|
|||||||
scan on
|
scan on
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
startup &
|
|
||||||
|
#Sadly needs to be run without '&' for now, since it otherwise breaks start_scan variable
|
||||||
|
startup
|
||||||
update_pair_list &
|
update_pair_list &
|
||||||
|
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
@ -111,11 +114,11 @@ pair(){
|
|||||||
new_devices="$( echo "$all_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
|
new_devices="$( echo "$all_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
|
||||||
bt_IDS="$( echo "$all_devices" | awk '{print $2}' )"
|
bt_IDS="$( echo "$all_devices" | awk '{print $2}' )"
|
||||||
else
|
else
|
||||||
echo "$paired_devices" > /tmp/paired_devices$$
|
#echo "$paired_devices" > /tmp/paired_devices$$
|
||||||
filtered_devices="$( echo "$all_devices" | grep -vf "/tmp/paired_devices$$")"
|
filtered_devices="$( echo "$all_devices" | grep -v "$paired_devices")"
|
||||||
bt_IDS="$( echo "$filtered_devices" | awk '{print $2}' )"
|
bt_IDS="$( echo "$filtered_devices" | awk '{print $2}' )"
|
||||||
new_devices="$( echo "$filtered_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
|
new_devices="$( echo "$filtered_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
|
||||||
rm /tmp/paired_devices$$
|
#rm /tmp/paired_devices$$
|
||||||
fi
|
fi
|
||||||
[ "$new_devices" = "" ] && options="rescan" || options=$(echo "$new_devices" && echo 'rescan')
|
[ "$new_devices" = "" ] && options="rescan" || options=$(echo "$new_devices" && echo 'rescan')
|
||||||
choice=$( echo "$options" | dmenu -l 10 -i -p 'pair with which device?' )
|
choice=$( echo "$options" | dmenu -l 10 -i -p 'pair with which device?' )
|
||||||
@ -169,12 +172,24 @@ case $choice in
|
|||||||
dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )
|
dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )
|
||||||
bluetoothctl trust "$dev_id"
|
bluetoothctl trust "$dev_id"
|
||||||
fi;;
|
fi;;
|
||||||
"disconnect") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?')
|
"disconnect")
|
||||||
if [ -n "$choice" ]; then
|
#search through all devices which are connected and only list those as options
|
||||||
dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}')
|
# shellcheck disable=SC1091
|
||||||
dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )
|
connected_devices="$( bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -E '(Alias:|Connected:)' | sed -e 'N;s/\n/;/;s/^.?*Alias: //' | grep "Connected: yes" | awk -F ';' '{print $1}' )"
|
||||||
bluetoothctl disconnect "$dev_id"
|
echo "$connected_devices"
|
||||||
fi;;
|
#only open dmenu prompt if there is more than one connected device
|
||||||
|
if [ "$( echo "$connected_devices" | wc -l )" -gt 1 ]
|
||||||
|
then
|
||||||
|
choice=$( echo "$connected_devices" | dmenu -l 10 -i -p 'remove which paired device?')
|
||||||
|
else
|
||||||
|
choice="$connected_devices"
|
||||||
|
fi
|
||||||
|
#only there was a choice (instead of canceling the dmenu)
|
||||||
|
if [ -n "$choice" ]; then
|
||||||
|
dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}')
|
||||||
|
dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )
|
||||||
|
bluetoothctl disconnect "$dev_id"
|
||||||
|
fi;;
|
||||||
"blacklist")
|
"blacklist")
|
||||||
choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'blacklist which paired device from selection?')
|
choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'blacklist which paired device from selection?')
|
||||||
if [ -n "$choice" ]; then
|
if [ -n "$choice" ]; then
|
||||||
|
@ -1,3 +1,2 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
ifinstalled python && python -iq -c "print('Welcome to the Calculator'); from numpy import *"
|
||||||
ifinstalled bc && echo "Welcome to the Calculator." && bc -lq
|
|
||||||
|
Loading…
Reference in New Issue
Block a user