* [PATCH BlueZ v2] zsh: amend completions
@ 2026-02-18 17:47 Ronan Pigott
2026-02-18 18:51 ` [BlueZ,v2] " bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Ronan Pigott @ 2026-02-18 17:47 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Ronan Pigott
First, use the correct completion return value.
The return value of a completion function is significant, if we fail to
return success additional completers may be invoked when they otherwise
should not be.
Also cleanup up the zsh completion, removing the redundant definition of
_bluetoothctl and using the _call_program helper where appropriate.
Finally, update the bluetoothctl invocations to be a little more robust
when parsing the output of device and list commands in case new output
lines are added.
---
Changes in v2:
- Dropped the hunk from src/shared/shell.c. I think it was left over
from a prior version of this patch on the branch where I had rebased
the input changes I submitted. This patch was originally submitted in
[1].
[1] https://marc.info/?l=linux-bluetooth&m=175072534107658&w=2
completion/zsh/_bluetoothctl | 133 ++++++++++++++++-------------------
1 file changed, 62 insertions(+), 71 deletions(-)
diff --git a/completion/zsh/_bluetoothctl b/completion/zsh/_bluetoothctl
index 610ca2b8d59c..b6f513376532 100644
--- a/completion/zsh/_bluetoothctl
+++ b/completion/zsh/_bluetoothctl
@@ -1,97 +1,88 @@
#compdef bluetoothctl
-__bluetoothctl() {
- bluetoothctl "$@" 2>/dev/null
-}
-
_bluezcomp_controller() {
local -a controllers
- bluetoothctl list |
- while read _ MAC NAME; do
- controllers+="${MAC//:/\\:}:${NAME//:/\\:}"
+ _call_program bluez-controller bluetoothctl list |
+ while read KIND MAC NAME FLAG; do
+ [[ $KIND == Controller ]] &&
+ controllers+=("${MAC//:/\\:}:${NAME//:/\\:}")
done
_describe -t controllers 'controller' controllers
}
_bluezcomp_device() {
local -a devices
- bluetoothctl devices |
- while read _ MAC NAME; do
- devices+="${MAC//:/\\:}:${NAME//:/\\:}"
+ _call_program bluez-device bluetoothctl devices |
+ while read KIND MAC NAME; do
+ [[ $KIND == Device ]] &&
+ devices+=("${MAC//:/\\:}:${NAME//:/\\:}")
done
_describe -t devices 'device' devices
}
_bluezcomp_agentcap() {
- local -a agent_options=(${(f)"$(__bluetoothctl agent help)"})
- agent_options=( "${(@)agent_options:#(on|off)}" )
- compadd -a agent_options
+ local -a agent_options=(${${(@f)"$(_call_program bluez-agent bluetoothctl agent help)"}:#(on|off)})
+ compadd "$@" - -a agent_options
}
_bluetoothctl_agent() {
- local -a agent_options=(${(f)"$(__bluetoothctl agent help)"})
- agent_options+=help
- compadd -a agent_options
+ local -a agent_options=(help ${(@f)"$(_call_program bluez-agent bluetoothctl agent help)"})
+ compadd "$@" - -a agent_options
}
-_bluetoothctl_advertise() {
- local -a ad_options=(${(f)"$(__bluetoothctl advertise help)"})
- ad_options+=help
- compadd -a ad_options
-}
+local -a toggle_commands=(
+ "discoverable" "pairable" "power" "scan"
+)
-_bluetoothctl() {
- local -a toggle_commands=(
- "discoverable" "pairable" "power" "scan"
- )
+local -a controller_commands=(
+ "select" "show"
+)
- local -a controller_commands=(
- "select" "show"
- )
+local -a device_commands=(
+ "block" "connect" "disconnect" "info"
+ "pair" "remove" "trust" "unblock" "untrust"
+)
- local -a device_commands=(
- "block" "connect" "disconnect" "info"
- "pair" "remove" "trust" "unblock" "untrust"
- )
+# Other commands may be handled by _bluetoothctl_$command
+local -a all_commands=( "${(@f)$(_call_program bluetoothctl bluetoothctl --zsh-complete help)}" )
- # Other commands may be handled by _bluetoothctl_$command
- local -a all_commands=( "${(@f)$(__bluetoothctl --zsh-complete help)}" )
+local curcontext=$curcontext state line ret=1
+_arguments -C \
+ + '(info)' \
+ {-h,--help}'[Show help message and exit]' \
+ {-v,--version}'--version[Show version info and exit]' \
+ + 'mod' \
+ '(info)'{-a+,--agent=}'[Register agent handler]:agent:_bluezcomp_agentcap' \
+ '(info)'{-t,--timeout}'[Timeout in seconds for non-interactive mode]' \
+ '(info)'{-m,--monitor}'[Enable monitor output]' \
+ + 'command' \
+ '(info):command:->command' \
+ '(info):: :->argument'
- local curcontext=$curcontext state line ret=1
- _arguments -C \
- + '(info)' \
- {-h,--help}'[Show help message and exit]' \
- {-v,--version}'--version[Show version info and exit]' \
- + 'mod' \
- '(info)'{-a+,--agent=}'[Register agent handler]:agent:_bluezcomp_agentcap' \
- '(info)'{-t,--timeout}'[Timeout in seconds for non-interactive mode]' \
- '(info)'{-m,--monitor}'[Enable monitor output]' \
- + 'command' \
- '(info):command:->command' \
- '(info):: :->argument'
-
- if [[ $state == "command" ]]; then
- _describe -t commands 'command' all_commands
- elif [[ $state == "argument" ]]; then
- if (( ! ${"${(@)all_commands%%:*}"[(I)${line[1]}]} )); then
- _message "Unknown bluetoothctl command: $line[1]"
- return 1;
- fi
-
- curcontext="${curcontext%:*:*}:bluetoothctl-$line[1]:"
- if ! _call_function ret _bluetoothctl_$line[1]; then
- case $line[1] in
- (${(~j.|.)toggle_commands})
- compadd on off
- ;;
- (${(~j.|.)device_commands})
- _bluezcomp_device
- ;;
- (${(~j.|.)controller_commands})
- _bluezcomp_controller
- ;;
- esac
- fi
- return ret
+if [[ $state == "command" ]]; then
+ _describe -t commands 'command' all_commands
+elif [[ $state == "argument" ]]; then
+ if (( ! ${"${(@)all_commands%%:*}"[(I)${line[1]}]} )); then
+ _message "Unknown bluetoothctl command: $line[1]"
+ return 1;
fi
-} && _bluetoothctl
+
+ curcontext="${curcontext%:*:*}:bluetoothctl-$line[1]:"
+ if ! _call_function ret _bluetoothctl_$line[1]; then
+ case $line[1] in
+ (advertise)
+ compadd - help on off type && ret=0
+ ;;
+ (${(~j.|.)toggle_commands})
+ compadd on off && ret=0
+ ;;
+ (${(~j.|.)device_commands})
+ _bluezcomp_device && ret=0
+ ;;
+ (${(~j.|.)controller_commands})
+ _bluezcomp_controller && ret=0
+ ;;
+ esac
+ fi
+ return ret
+fi
base-commit: eae36399e75807dcf3d88d9af18909288fa71ee4
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: [BlueZ,v2] zsh: amend completions
2026-02-18 17:47 [PATCH BlueZ v2] zsh: amend completions Ronan Pigott
@ 2026-02-18 18:51 ` bluez.test.bot
0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-02-18 18:51 UTC (permalink / raw)
To: linux-bluetooth, ronan
[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1055282
---Test result---
Test Summary:
CheckPatch PENDING 0.32 seconds
GitLint PENDING 0.40 seconds
BuildEll PASS 21.44 seconds
BluezMake PASS 660.15 seconds
MakeCheck PASS 19.03 seconds
MakeDistcheck PASS 252.47 seconds
CheckValgrind PASS 303.68 seconds
CheckSmatch PASS 367.78 seconds
bluezmakeextell PASS 185.58 seconds
IncrementalBuild PENDING 0.43 seconds
ScanBuild PASS 1072.87 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-02-18 18:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-18 17:47 [PATCH BlueZ v2] zsh: amend completions Ronan Pigott
2026-02-18 18:51 ` [BlueZ,v2] " bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox