aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/bash-completion
diff options
context:
space:
mode:
authorJakub Kicinski <jakub.kicinski@netronome.com>2018-06-28 17:41:42 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-06-30 19:01:50 -0400
commit121c58bed01a45043381ce52b8556e851dbaa123 (patch)
tree4f77c5ca28c58d7c6330a8b0a30b33c5b3d94a77 /tools/bpf/bpftool/bash-completion
parentef347a340b1a8507c22ee3cf981cd5cd64188431 (diff)
tools: bpftool: deal with options upfront
Remove options (in getopt() sense, i.e. starting with a dash like -n or --NAME) while parsing arguments for bash completions. This allows us to refer to position-dependent parameters better, and complete options at any point. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf/bpftool/bash-completion')
-rw-r--r--tools/bpf/bpftool/bash-completion/bpftool32
1 files changed, 21 insertions, 11 deletions
diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool
index b0b8022d3570..fffd76f4998b 100644
--- a/tools/bpf/bpftool/bash-completion/bpftool
+++ b/tools/bpf/bpftool/bash-completion/bpftool
@@ -153,6 +153,13 @@ _bpftool()
153 local cur prev words objword 153 local cur prev words objword
154 _init_completion || return 154 _init_completion || return
155 155
156 # Deal with options
157 if [[ ${words[cword]} == -* ]]; then
158 local c='--version --json --pretty --bpffs'
159 COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
160 return 0
161 fi
162
156 # Deal with simplest keywords 163 # Deal with simplest keywords
157 case $prev in 164 case $prev in
158 help|hex|opcodes|visual) 165 help|hex|opcodes|visual)
@@ -172,20 +179,23 @@ _bpftool()
172 ;; 179 ;;
173 esac 180 esac
174 181
175 # Search for object and command 182 # Remove all options so completions don't have to deal with them.
176 local object command cmdword 183 local i
177 for (( cmdword=1; cmdword < ${#words[@]}-1; cmdword++ )); do 184 for (( i=1; i < ${#words[@]}; )); do
178 [[ -n $object ]] && command=${words[cmdword]} && break 185 if [[ ${words[i]::1} == - ]]; then
179 [[ ${words[cmdword]} != -* ]] && object=${words[cmdword]} 186 words=( "${words[@]:0:i}" "${words[@]:i+1}" )
187 [[ $i -le $cword ]] && cword=$(( cword - 1 ))
188 else
189 i=$(( ++i ))
190 fi
180 done 191 done
192 cur=${words[cword]}
193 prev=${words[cword - 1]}
181 194
182 if [[ -z $object ]]; then 195 local object=${words[1]} command=${words[2]}
196
197 if [[ -z $object || $cword -eq 1 ]]; then
183 case $cur in 198 case $cur in
184 -*)
185 local c='--version --json --pretty --bpffs'
186 COMPREPLY=( $( compgen -W "$c" -- "$cur" ) )
187 return 0
188 ;;
189 *) 199 *)
190 COMPREPLY=( $( compgen -W "$( bpftool help 2>&1 | \ 200 COMPREPLY=( $( compgen -W "$( bpftool help 2>&1 | \
191 command sed \ 201 command sed \