Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bpftool: Add bash completion for program signing options

Commit 40863f4d6ef2 ("bpftool: Add support for signing BPF programs")
added new options for "bpftool prog load" and "bpftool gen skeleton".
This commit brings the relevant update to the bash completion file.

We rework slightly the processing of options to make completion more
resilient for options that take an argument.

Signed-off-by: Quentin Monnet <qmo@kernel.org>
Link: https://lore.kernel.org/r/20250923103802.57695-1-qmo@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Quentin Monnet and committed by
Alexei Starovoitov
0d3bf643 f0b5c149

+17 -9
+17 -9
tools/bpf/bpftool/bash-completion/bpftool
··· 262 262 # Deal with options 263 263 if [[ ${words[cword]} == -* ]]; then 264 264 local c='--version --json --pretty --bpffs --mapcompat --debug \ 265 - --use-loader --base-btf' 265 + --use-loader --base-btf --sign -i -k' 266 266 COMPREPLY=( $( compgen -W "$c" -- "$cur" ) ) 267 267 return 0 268 268 fi ··· 283 283 _sysfs_get_netdevs 284 284 return 0 285 285 ;; 286 - file|pinned|-B|--base-btf) 286 + file|pinned|-B|--base-btf|-i|-k) 287 287 _filedir 288 288 return 0 289 289 ;; ··· 296 296 # Remove all options so completions don't have to deal with them. 297 297 local i pprev 298 298 for (( i=1; i < ${#words[@]}; )); do 299 - if [[ ${words[i]::1} == - ]] && 300 - [[ ${words[i]} != "-B" ]] && [[ ${words[i]} != "--base-btf" ]]; then 301 - words=( "${words[@]:0:i}" "${words[@]:i+1}" ) 302 - [[ $i -le $cword ]] && cword=$(( cword - 1 )) 303 - else 304 - i=$(( ++i )) 305 - fi 299 + case ${words[i]} in 300 + # Remove option and its argument 301 + -B|--base-btf|-i|-k) 302 + words=( "${words[@]:0:i}" "${words[@]:i+2}" ) 303 + [[ $i -le $(($cword + 1)) ]] && cword=$(( cword - 2 )) 304 + ;; 305 + # No argument, remove option only 306 + -*) 307 + words=( "${words[@]:0:i}" "${words[@]:i+1}" ) 308 + [[ $i -le $cword ]] && cword=$(( cword - 1 )) 309 + ;; 310 + *) 311 + i=$(( ++i )) 312 + ;; 313 + esac 306 314 done 307 315 cur=${words[cword]} 308 316 prev=${words[cword - 1]}