Only lists connected devices in disconnect menu
Does not list all paired devices anymore Also, if there is only one connected device, immedieately disconnect that device modified: README.md modified: bt
This commit is contained in:
		@@ -52,4 +52,5 @@ If you have troubles with an uninstall, _additionally_ run `which bt | xargs rm`
 | 
			
		||||
- update bthandler internal paired devices list if something new shows up via `bluetoothctl paired-devices` not already listed in the paired devices file -> **Implemented**
 | 
			
		||||
- only show disconnect option if devices are already connected -> **Implemented**
 | 
			
		||||
- find a way to get something similar to `grep -vf` without the need of temp files.
 | 
			
		||||
- only list connected devices to disconnect from, not all paired devices
 | 
			
		||||
- only list connected devices to disconnect from, not all paired devices -> **Implemented**
 | 
			
		||||
- only list not trusted devices in trust menu
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								bt
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								bt
									
									
									
									
									
								
							@@ -172,17 +172,23 @@ case $choice in
 | 
			
		||||
			dev_id=$( echo "$bt_IDS" | nl | grep -P "^.*$dev_no\t" | awk '{print $2}' )
 | 
			
		||||
			bluetoothctl trust "$dev_id"
 | 
			
		||||
		fi;;
 | 
			
		||||
	"disconnect") if [ "$( echo "$paired_devices" | wc -l )" -gt 1 ]
 | 
			
		||||
		      then
 | 
			
		||||
			choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'remove which paired device?')
 | 
			
		||||
	              else
 | 
			
		||||
			      choice="$(paired_devices)"
 | 
			
		||||
		      fi
 | 
			
		||||
			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;;
 | 
			
		||||
	"disconnect")
 | 
			
		||||
		#search through all devices which are connected and only list those as options
 | 
			
		||||
		# shellcheck disable=SC1091
 | 
			
		||||
		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}' )"
 | 
			
		||||
		#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")
 | 
			
		||||
		choice=$( echo "$paired_devices" | dmenu -l 10 -i -p 'blacklist which paired device from selection?')
 | 
			
		||||
		if [ -n "$choice" ]; then
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user