Skip to content

Commit

Permalink
bpftool: Add link bash completions
Browse files Browse the repository at this point in the history
Extend bpftool's bash-completion script to handle new link command and its
sub-commands.

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200429001614.1544-11-andriin@fb.com
  • Loading branch information
Andrii Nakryiko authored and Alexei Starovoitov committed Apr 29, 2020
1 parent 7464d01 commit 5d085ad
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tools/bpf/bpftool/bash-completion/bpftool
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ _bpftool_get_btf_ids()
command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
}

_bpftool_get_link_ids()
{
COMPREPLY+=( $( compgen -W "$( bpftool -jp link 2>&1 | \
command sed -n 's/.*"id": \(.*\),$/\1/p' )" -- "$cur" ) )
}

_bpftool_get_obj_map_names()
{
local obj
Expand Down Expand Up @@ -1082,6 +1088,39 @@ _bpftool()
;;
esac
;;
link)
case $command in
show|list|pin)
case $prev in
id)
_bpftool_get_link_ids
return 0
;;
esac
;;
esac

local LINK_TYPE='id pinned'
case $command in
show|list)
[[ $prev != "$command" ]] && return 0
COMPREPLY=( $( compgen -W "$LINK_TYPE" -- "$cur" ) )
return 0
;;
pin)
if [[ $prev == "$command" ]]; then
COMPREPLY=( $( compgen -W "$LINK_TYPE" -- "$cur" ) )
else
_filedir
fi
return 0
;;
*)
[[ $prev == $object ]] && \
COMPREPLY=( $( compgen -W 'help pin show list' -- "$cur" ) )
;;
esac
;;
esac
} &&
complete -F _bpftool bpftool
Expand Down

0 comments on commit 5d085ad

Please sign in to comment.