2020-07-16 10:42 UTC-0700 ~ Yonghong Song <yhs@xxxxxx> > > > On 7/16/20 9:39 AM, Quentin Monnet wrote: >> 2020-07-13 09:17 UTC-0700 ~ Yonghong Song <yhs@xxxxxx> [...] >> Could you please also update the bash completion? > > This is always my hardest part! In this case it is > bpftool iter pin <filedir> <filedir> [map MAP] > > Any particular existing bpftool implementation I can imitate? I would say the closest/easiest to reuse we have would be completion for the MAP part in either bpftool prog attach PROG ATTACH_TYPE [MAP] or bpftool map pin MAP FILE But I'll save you some time, I gave it a go and this is what I came up with: ------ diff --git a/tools/bpf/bpftool/bash-completion/bpftool b/tools/bpf/bpftool/bash-completion/bpftool index 25b25aca1112..6640e18096a8 100644 --- a/tools/bpf/bpftool/bash-completion/bpftool +++ b/tools/bpf/bpftool/bash-completion/bpftool @@ -613,9 +613,26 @@ _bpftool() esac ;; iter) + local MAP_TYPE='id pinned name' case $command in pin) - _filedir + case $prev in + $command) + _filedir + ;; + id) + _bpftool_get_map_ids + ;; + name) + _bpftool_get_map_names + ;; + pinned) + _filedir + ;; + *) + _bpftool_one_of_list $MAP_TYPE + ;; + esac return 0 ;; *) ------ So if we complete "bpftool iter pin", if we're right after "pin" we still complete with file names (for the object file to pin). If we're after one of the map keywords (id|name|pinned), complete with map ids or map names or file names, depending on the case. For other cases (i.e. after object file to pin), offer the map keywords (id|name|pinned). Feel free to reuse. Best, Quentin