Skip to content

Commit 0d3bf64

Browse files
qmonnetAlexei Starovoitov
authored andcommitted
bpftool: Add bash completion for program signing options
Commit 40863f4 ("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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent f0b5c14 commit 0d3bf64

File tree

1 file changed

+17
-9
lines changed
  • tools/bpf/bpftool/bash-completion

1 file changed

+17
-9
lines changed

tools/bpf/bpftool/bash-completion/bpftool

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ _bpftool()
262262
# Deal with options
263263
if [[ ${words[cword]} == -* ]]; then
264264
local c='--version --json --pretty --bpffs --mapcompat --debug \
265-
--use-loader --base-btf'
265+
--use-loader --base-btf --sign -i -k'
266266
COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
267267
return 0
268268
fi
@@ -283,7 +283,7 @@ _bpftool()
283283
_sysfs_get_netdevs
284284
return 0
285285
;;
286-
file|pinned|-B|--base-btf)
286+
file|pinned|-B|--base-btf|-i|-k)
287287
_filedir
288288
return 0
289289
;;
@@ -296,13 +296,21 @@ _bpftool()
296296
# Remove all options so completions don't have to deal with them.
297297
local i pprev
298298
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
306314
done
307315
cur=${words[cword]}
308316
prev=${words[cword - 1]}

0 commit comments

Comments
 (0)