#compdef bluetooth-setup # ZSH completion for bluetooth-setup # Place this file in /usr/local/share/zsh/site-functions/_bluetooth-setup _bluetooth-setup() { local curcontext="$curcontext" state line typeset -A opt_args _arguments -C \ '1: :->command' \ '2: :->arg' \ && return 0 case $state in command) local -a commands commands=( 'scan:Scan for nearby Bluetooth devices' 'pair:Pair with a device' 'connect:Connect to a paired device' 'disconnect:Disconnect from device(s)' 'remove:Remove/forget a paired device' 'status:Show Bluetooth status' 'list-paired:List paired devices' 'list:List paired devices' 'power:Enable or disable Bluetooth' 'help:Show help information' ) _describe -t commands 'bluetooth-setup command' commands ;; arg) case $line[1] in pair) # Complete with discovered devices (MAC addresses) local -a devices devices=(${(f)"$(bluetoothctl devices 2>/dev/null | awk '{print $2":"$3}' | sed 's/:$//')"}) _describe -t devices 'available devices' devices ;; connect|disconnect|remove|forget) # Complete with paired devices (MAC addresses) local -a paired paired=(${(f)"$(bluetoothctl paired-devices 2>/dev/null | awk '{print $2":"substr($0, index($0,$3))}')"}) _describe -t paired 'paired devices' paired ;; power) # Complete with on/off local -a power_states power_states=('on:Enable Bluetooth' 'off:Disable Bluetooth') _describe -t power_states 'power state' power_states ;; esac ;; esac return 0 } _bluetooth-setup "$@"