likeatree

linux下 为自己编写的程序 添加tab自动补全功能 入门


complete

  1. 在我的tmp下随便写了一个a.sh, 为他补全
  2. edit /etc/bash_completion.d/foo
_foo()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--help --verbose --version"

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _foo /home/cc/tmp/comp/a.sh
  1. source foo后
    表现为
cc@PC:~/tmp/comp$ ./a.sh 
a.sh       comp1.sh   comp-a.sh  x-chen     
cc@PC:~/tmp/comp$ /home/cc/tmp/comp/a.sh --
--help     --verbose  --version  

4.undo以上操作???
我猜想是改一下步骤2的函数体继续做以下步骤就好

================================对x的complete完全正确步骤

  1. edit /etc/bash_completion.d/xchencomp
_x_chen_comp() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="qtcreator idea lantern clion"

    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    return 0
}
complete -F _x_chen_comp x
  1. source xchencomp

  2. 愉快使用x命令打开qtcreator等软件 _

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-17
  • 2021-11-21
  • 2021-11-02
  • 2021-08-11
  • 2021-05-27
猜你喜欢
  • 2021-11-06
  • 2021-12-05
  • 2021-12-12
  • 2021-12-03
相关资源
相似解决方案