|
Packit |
34410b |
#compdef bluetoothctl
|
|
Packit |
34410b |
|
|
Packit |
34410b |
__bluetoothctl() {
|
|
Packit |
34410b |
bluetoothctl "$@" 2>/dev/null
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
_bluezcomp_controller() {
|
|
Packit |
34410b |
local -a controllers
|
|
Packit |
34410b |
bluetoothctl list |
|
|
Packit |
34410b |
while read _ MAC NAME; do
|
|
Packit |
34410b |
controllers+="${MAC//:/\\:}:${NAME//:/\\:}"
|
|
Packit |
34410b |
done
|
|
Packit |
34410b |
_describe -t controllers 'controller' controllers
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
_bluezcomp_device() {
|
|
Packit |
34410b |
local -a devices
|
|
Packit |
34410b |
bluetoothctl devices |
|
|
Packit |
34410b |
while read _ MAC NAME; do
|
|
Packit |
34410b |
devices+="${MAC//:/\\:}:${NAME//:/\\:}"
|
|
Packit |
34410b |
done
|
|
Packit |
34410b |
_describe -t devices 'device' devices
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
_bluezcomp_agentcap() {
|
|
Packit |
34410b |
local -a agent_options=(${(f)"$(__bluetoothctl agent help)"})
|
|
Packit |
34410b |
agent_options=( "${(@)agent_options:#(on|off)}" )
|
|
Packit |
34410b |
compadd -a agent_options
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
_bluetoothctl_agent() {
|
|
Packit |
34410b |
local -a agent_options=(${(f)"$(__bluetoothctl agent help)"})
|
|
Packit |
34410b |
agent_options+=help
|
|
Packit |
34410b |
compadd -a agent_options
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
_bluetoothctl_advertise() {
|
|
Packit |
34410b |
local -a ad_options=(${(f)"$(__bluetoothctl advertise help)"})
|
|
Packit |
34410b |
ad_options+=help
|
|
Packit |
34410b |
compadd -a ad_options
|
|
Packit |
34410b |
}
|
|
Packit |
34410b |
|
|
Packit |
34410b |
_bluetoothctl() {
|
|
Packit |
34410b |
local -a toggle_commands=(
|
|
Packit |
34410b |
"discoverable" "pairable" "power" "scan"
|
|
Packit |
34410b |
)
|
|
Packit |
34410b |
|
|
Packit |
34410b |
local -a controller_commands=(
|
|
Packit |
34410b |
"select" "show"
|
|
Packit |
34410b |
)
|
|
Packit |
34410b |
|
|
Packit |
34410b |
local -a device_commands=(
|
|
Packit |
34410b |
"block" "connect" "disconnect" "info"
|
|
Packit |
34410b |
"pair" "remove" "trust" "unblock" "untrust"
|
|
Packit |
34410b |
)
|
|
Packit |
34410b |
|
|
Packit |
34410b |
# Other commands may be handled by _bluetoothctl_$command
|
|
Packit |
34410b |
local -a all_commands=( "${(@f)$(__bluetoothctl --zsh-complete help)}" )
|
|
Packit |
34410b |
|
|
Packit |
34410b |
local curcontext=$curcontext state line ret=1
|
|
Packit |
34410b |
_arguments -C \
|
|
Packit |
34410b |
+ '(info)' \
|
|
Packit |
34410b |
{-h,--help}'[Show help message and exit]' \
|
|
Packit |
34410b |
{-v,--version}'--version[Show version info and exit]' \
|
|
Packit |
34410b |
+ 'mod' \
|
|
Packit |
34410b |
'(info)'{-a+,--agent=}'[Register agent handler]:agent:_bluezcomp_agentcap' \
|
|
Packit |
34410b |
'(info)'{-t,--timeout}'[Timeout in seconds for non-interactive mode]' \
|
|
Packit |
34410b |
'(info)'{-m,--monitor}'[Enable monitor output]' \
|
|
Packit |
34410b |
+ 'command' \
|
|
Packit |
34410b |
'(info):command:->command' \
|
|
Packit |
34410b |
'(info):: :->argument' \
|
|
Packit |
34410b |
': :_message "no more arguments"'
|
|
Packit |
34410b |
|
|
Packit |
34410b |
if [[ $state == "command" ]]; then
|
|
Packit |
34410b |
_describe -t commands 'command' all_commands
|
|
Packit |
34410b |
elif [[ $state == "argument" ]]; then
|
|
Packit |
34410b |
if (( ! ${"${(@)all_commands%%:*}"[(I)${line[1]}]} )); then
|
|
Packit |
34410b |
_message "Unknown bluetoothctl command: $line[1]"
|
|
Packit |
34410b |
return 1;
|
|
Packit |
34410b |
fi
|
|
Packit |
34410b |
|
|
Packit |
34410b |
curcontext="${curcontext%:*:*}:bluetoothctl-$line[1]:"
|
|
Packit |
34410b |
if ! _call_function ret _bluetoothctl_$line[1]; then
|
|
Packit |
34410b |
case $line[1] in
|
|
Packit |
34410b |
(${(~j.|.)toggle_commands})
|
|
Packit |
34410b |
compadd on off
|
|
Packit |
34410b |
;;
|
|
Packit |
34410b |
(${(~j.|.)device_commands})
|
|
Packit |
34410b |
_bluezcomp_device
|
|
Packit |
34410b |
;;
|
|
Packit |
34410b |
(${(~j.|.)controller_commands})
|
|
Packit |
34410b |
_bluezcomp_controller
|
|
Packit |
34410b |
;;
|
|
Packit |
34410b |
esac
|
|
Packit |
34410b |
fi
|
|
Packit |
34410b |
return ret
|
|
Packit |
34410b |
fi
|
|
Packit |
34410b |
} && _bluetoothctl
|