-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add completion for bluetoothctl #742
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||||||||||
# bluetoothctl(1) completion -*- shell-script -*- | ||||||||||||||
|
||||||||||||||
_bluetoothctl() | ||||||||||||||
{ | ||||||||||||||
local cur=${COMP_WORDS[COMP_CWORD]} | ||||||||||||||
local prev=${COMP_WORDS[COMP_CWORD-1]} | ||||||||||||||
if [[ "$COMP_CWORD" == "1" ]]; then | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The same applies to the later lines testing |
||||||||||||||
# Parse help for list of commands and remove ansi colors | ||||||||||||||
COMPREPLY=( $( compgen -W "$(bluetoothctl help | sed -n '/ /{s/\x1B\[[0-9;]*[a-zA-Z]//g;s/\x01//g;s/\x02//g;s/ .*//p}')" -- $cur)) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Suggested change
Suggested change
These comments also apply to the later lines that contain the same structure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, it might just be better to not use sed at all. I think this should be doable in bash only. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think either works, so you can use what you like. |
||||||||||||||
return | ||||||||||||||
fi | ||||||||||||||
if [[ "$COMP_CWORD" == "2" ]]; then | ||||||||||||||
case "$prev" in | ||||||||||||||
info|pair|trust|untrust|block|unblock|remove|connect|disconnect) | ||||||||||||||
# Return a device to complete | ||||||||||||||
COMPREPLY=( $( compgen -W "$(bluetoothctl devices|awk '{print $2}')" -- $cur)) | ||||||||||||||
;; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
show|select) | ||||||||||||||
# Return a controller address | ||||||||||||||
COMPREPLY=( $( compgen -W "$(bluetoothctl list|awk '{print $2}')" -- $cur)) | ||||||||||||||
;; | ||||||||||||||
power|pairable|discoverable|scan) | ||||||||||||||
COMPREPLY=( $( compgen -W "on off" -- $cur)) | ||||||||||||||
;; | ||||||||||||||
agent) | ||||||||||||||
COMPREPLY=( $( compgen -W "on off capability" -- $cur)) | ||||||||||||||
;; | ||||||||||||||
advertise) | ||||||||||||||
COMPREPLY=( $( compgen -W "on off type" -- $cur)) | ||||||||||||||
;; | ||||||||||||||
esac | ||||||||||||||
fi | ||||||||||||||
if [[ ${COMP_WORDS[1]} == "menu" ]]; then | ||||||||||||||
if [[ "$COMP_CWORD" == "2" ]]; then | ||||||||||||||
# List out submenues | ||||||||||||||
COMPREPLY=( $(compgen -W "$(bluetoothctl help | sed -n '/Submenu/{s/\x1B\[[0-9;]*[a-zA-Z]//g;s/\x02//g;s/\x01//;s/ .*//p}')" -- $cur)) | ||||||||||||||
return | ||||||||||||||
fi | ||||||||||||||
if [[ "$COMP_CWORD" == "3" ]]; then | ||||||||||||||
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
# Parse submenu and return commands. | ||||||||||||||
COMPREPLY=( $( compgen -W "$(bluetoothctl menu $prev | sed -n '/ /{s/\x1B\[[0-9;]*[a-zA-Z]//g;s/\x01//g;s/\x02//g;s/ .*//p}' )" -- $cur)) | ||||||||||||||
fi | ||||||||||||||
fi | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||||||||||||||
# ex: filetype=sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you intend to use the auto-loading mechanism of bash-completion (i.e., putting the file in the
completions
directory and lettingbash-completion
load it automatically on demand), I suggest using_init_completion
for the initialization (as done in other completions). It doesn't only provide a better extraction of the words but also the contextual completions for the variable names and redirections. It might also be used bybash-completion
for hooks in the future.