Commit 5d085ad2 authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Alexei Starovoitov
Browse files

bpftool: Add link bash completions



Extend bpftool's bash-completion script to handle new link command and its
sub-commands.

Signed-off-by: default avatarAndrii Nakryiko <andriin@fb.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20200429001614.1544-11-andriin@fb.com
parent 7464d013
Loading
Loading
Loading
Loading
+39 −0
Original line number Diff line number Diff line
@@ -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
@@ -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