various updates

modified:   .config/coc/extensions/db.json
	modified:   .config/gtk-2.0/gtkfilechooser.ini
	modified:   .local/bin/bt
	deleted:    .local/bin/tools/startanki
This commit is contained in:
Alexander Bocken 2020-07-06 10:00:51 +02:00
parent 46d9d9eb4c
commit 939781b342
4 changed files with 82 additions and 48 deletions

View File

@ -1,3 +1,3 @@
{ {
"lastUpdate": 1593852197191 "lastUpdate": 1594016620119
} }

View File

@ -2,8 +2,8 @@
LocationMode=path-bar LocationMode=path-bar
ShowHidden=false ShowHidden=false
ShowSizeColumn=true ShowSizeColumn=true
GeometryX=1105 GeometryX=1104
GeometryY=500 GeometryY=522
GeometryWidth=990 GeometryWidth=990
GeometryHeight=800 GeometryHeight=800
SortColumn=modified SortColumn=modified

View File

@ -1,16 +1,15 @@
#!/bin/bash #!/bin/sh
#wait time to discover new devices in seconds
SCAN_PERIOD=5 SCAN_PERIOD=5
AUTOTRUST=false AUTOTRUST=false
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
PAIRLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/paired PAIRLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/paired
actions="pair actions="pair
disconnect
unpair" unpair"
[ "$AUTOTRUST" = false ] && actions+=" [ "$AUTOTRUST" = false ] && actions="${actions}
trust" trust"
#Checks for necessary programs to be present. Very unlikely not to be present but let's just err on the safer side. #Checks for necessary programs to be present. Very unlikely not to be present but let's just err on the safer side.
@ -42,10 +41,35 @@ scan(){
fi fi
} }
#Check bluetoothctl paired-devices for new devices to be hardcoded into pair list
update_pair_list(){
btctl_paired_devices="$(bluetoothctl paired-devices)"
if [ -n "$btctl_paired_devices" ]
then
btctl_not_in_list="$( echo "$btctl_paired_devices" | grep -vf "$PAIRLIST")"
[ -n "$btctl_not_in_list" ] && echo "$btctl_not_in_list" >> "$PAIRLIST"
fi
}
#start scanning as early as possible to speed up pairing process #start scanning as early as possible to speed up pairing process
#=> maybe use an option to do this? Otherwise ever invocation of bt powers on the controller. #In function to more quickly display the menu
startup(){
if $AUTOSCAN
then
power on power on
scan on scan on
fi
}
startup &
update_pair_list &
# shellcheck disable=SC1091
if bluetoothctl devices | awk '{print "bluetoothctl info "$2}' | . /dev/stdin | grep -q "Connected: yes"
then
actions="$(printf "disconnect\n%s" "$actions")"
fi
#Compile list of all Bluetooth IDS of paired devices (from bluetoothctl and from hardcoded list) #Compile list of all Bluetooth IDS of paired devices (from bluetoothctl and from hardcoded list)
bt_IDS="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{print $2}' )" bt_IDS="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u | awk '{print $2}' )"
@ -56,10 +80,11 @@ paired_devices="$( ( bluetoothctl paired-devices && cat "$PAIRLIST" ) | sort -u
disp_devices="$( echo "$paired_devices" | grep -vf "$BLACKLIST" )" disp_devices="$( echo "$paired_devices" | grep -vf "$BLACKLIST" )"
#detects current power mode of controller and adjusts options accordingly #detects current power mode of controller and adjusts options accordingly
powerstatus="$( bluetoothctl show | grep Powered | awk '{print $2}' )"
poweroption="$( echo "$powerstatus" | sed 's/yes/power off/; s/no/power on/' )" poweroption="$( echo "$powerstatus" | sed 's/yes/power off/; s/no/power on/' )"
#Don't print empty device list, removes unnecessary empty choice in dmenu #Don't print empty device list, removes unnecessary empty choice in dmenu
[ "$disp_devices" = "" ] && choice=$( printf "%s\n%s" "$poweroption" "$actions" | dmenu -i -p 'What BT action would you like to perform:' ) [ "$disp_devices" = "" ] && choice=$( printf "%s\n%s" "$actions" "$poweroption" | dmenu -i -p 'What BT action would you like to perform:' )
[ "$disp_devices" != "" ] && choice=$( ( echo "$disp_devices" && printf "%s\n%s" "$poweroption" "$actions" ) | dmenu -i -p 'What BT action would you like to perform:' ) [ "$disp_devices" != "" ] && choice=$( ( echo "$disp_devices" && printf "%s\n%s" "$actions" "$poweroption" ) | dmenu -i -p 'What BT action would you like to perform:' )
cleanup(){ cleanup(){
scan off scan off
@ -81,44 +106,45 @@ pair(){
sleep "$sleep_period" sleep "$sleep_period"
fi fi
echo paired_devices:"$paired_devices". all_devices="$( bluetoothctl devices )"
echo paired_devices:$paired_devices. if [ "$paired_devices" = "" ]; then
if [ $paired_devices = "" ]; then new_devices="$( echo "$all_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
new_devices="$( bluetoothctl devices | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' | grep -vf "<(echo $paired_devices)" )" bt_IDS="$( echo "$all_devices" | awk '{print $2}' )"
else else
new_devices="$( bluetoothctl devices | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )" echo "$paired_devices" > /tmp/paired_devices$$
filtered_devices="$( echo "$all_devices" | grep -vf "/tmp/paired_devices$$")"
bt_IDS="$( echo "$filtered_devices" | awk '{print $2}' )"
new_devices="$( echo "$filtered_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
rm /tmp/paired_devices$$
fi fi
echo new_devices:"$new_devices". [ "$new_devices" = "" ] && options="rescan" || options=$(echo "$new_devices" && echo 'rescan')
echo new_devices:$new_devices.
[ $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?' )
if [ -n "$choice" ]; then if [ -n "$choice" ]; then
if [ "$choice" = "rescan" ]; then if [ "$choice" = "rescan" ]; then
start_scan="$( date +'%s')" start_scan="$( date +'%s')"
pair pair
fi else
bt_IDS="$( bluetoothctl devices | awk '{print $2}' )"
dev_no=$( echo "$new_devices" | nl | grep "$choice" | awk '{print $1}') dev_no=$( echo "$new_devices" | nl | grep "$choice" | awk '{print $1}')
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}' )
#only attempt to connect if pairing succeeds
bluetoothctl pair "$dev_id" && sleep 2 bluetoothctl pair "$dev_id" && ( pair_succesful=true && bluetoothctl connect "$dev_id" ) || pair_succesful=false
bluetoothctl connect "$dev_id"
if $AUTOTRUST; then if $AUTOTRUST; then
bluetoothctl trust "$dev_id" bluetoothctl trust "$dev_id"
fi fi
#if device is not already hard coded as paired, add to paired devices list #if device is not already hard coded as paired, add to paired devices list
if [ $( grep "$dev_id" "$PAIRLIST") = "" ] if [ "$( grep "$dev_id" "$PAIRLIST")" = "" ] || [ "$(wc -l "$PAIRLIST")" -eq 0 ] && $pair_succesful
then then
echo to be added to "$PAIRLIST": echo to be added to "$PAIRLIST":
echo Device "$dev_id" "$choice" echo Device "$dev_id" "$choice"
echo Device "$dev_id" "$choice" >> "$PAIRLIST" echo Device "$dev_id" "$choice" >> "$PAIRLIST"
fi fi
fi fi
fi
} }
case $choice in case $choice in
"turn on") bluetoothctl power on;; "power on") bluetoothctl power on;;
"turn off") bluetoothctl power off;; "power off") bluetoothctl power off;;
"scan on") bluetoothctl power on && echo power on && sleep 2 "scan on") bluetoothctl power on && echo power on && sleep 2
([ -n "$TERMINAL" ] && $TERMINAL -e bluetoothctl scan on ) || st bluetoothctl scan on;; ([ -n "$TERMINAL" ] && $TERMINAL -e bluetoothctl scan on ) || st bluetoothctl scan on;;
"pair") pair;; "pair") pair;;
@ -129,7 +155,13 @@ case $choice in
bluetoothctl remove "$dev_id" bluetoothctl remove "$dev_id"
#remove device to unpair from hard coded paired devices list #remove device to unpair from hard coded paired devices list
new_paired_list="$( grep -v "$dev_id" "$PAIRLIST" )" new_paired_list="$( grep -v "$dev_id" "$PAIRLIST" )"
echo "$new_paired_list" > "$PAIRLIST" #needs to be done with temp var, can't read from file and pipe into it at the same time if [ "$new_paired_list" != "" ]
then
echo "$new_paired_list" > "$PAIRLIST"
else
rm -rf "$PAIRLIST"
touch "$PAIRLIST"
fi
fi;; fi;;
"trust") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?') "trust") choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?')
if [ -n "$choice" ]; then if [ -n "$choice" ]; then
@ -143,12 +175,18 @@ 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 disconnect "$dev_id" bluetoothctl disconnect "$dev_id"
fi;; fi;;
"blacklist")
choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'blacklist which paired device from selection?')
if [ -n "$choice" ]; then
echo "$choice" >> "$BLACKLIST"
fi;;
*) *)
echo "$choice" echo "$choice"
dev_no=$( echo "$paired_devices" | nl | grep -P "[0-9]+\t$choice$" | awk '{print $1}') 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}') [ "$dev_no" != "" ] && dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}')
bluetoothctl power on if [ -n "$dev_id" ]; then
power on
bluetoothctl pair "$dev_id" bluetoothctl pair "$dev_id"
bluetoothctl connect "$dev_id";; bluetoothctl connect "$dev_id"
fi;;
esac esac
cleanup

View File

@ -1,4 +0,0 @@
#!/bin/bash
anki &
sleep 2
hover center