How to reuse rostopic's completion function fo

2019-08-19 04:41发布

Defined bash function rte():

$ function rte(){ rostopic echo $@ ; };

and attempted to use rostopic's completion function

$ complete -p rostopic
complete -F _roscomplete_rostopic rostopic

via the command:

$ complete -F _roscomplete_rostopic rte

The above setting can be verified as follows:

$ complete -p rte
complete -F _roscomplete_rostopic rte

However, rte <partial input><tab> does not offer completions.

Question: How to get rte() to use rostopic's completion? I guess when rte()'s completion calls rostopic's completion, the context echo needs to be provided to rostopic's completion (i.e., COMP_WORDS needs to contain echo).

1条回答
女痞
2楼-- · 2019-08-19 04:43

Figured out a solution -- now have the following in .bashrc:

function rte(){ rostopic echo "$@" ; };

complete -F _mycomplete_ rte

function _mycomplete_()
{
    local fragment=${COMP_WORDS[COMP_CWORD]}
    COMP_CWORD=2
    COMP_WORDS[0]="rostopic"
    COMP_WORDS[1]="echo"
    COMP_WORDS[2]=$fragment
    COMP_LINE="rostopic echo $fragment"

    _roscomplete_rostopic;
}
查看更多
登录 后发表回答