linux下 为自己编写的程序 添加tab自动补全功能 入门
complete
- 在我的tmp下随便写了一个a.sh, 为他补全
- edit
/etc/bash_completion.d/foo
_foo()
{local cur prev optsCOMPREPLY=()cur="${COMP_WORDS[COMP_CWORD]}"prev="${COMP_WORDS[COMP_CWORD-1]}"opts="--help --verbose --version"if [[ ${cur} == -* ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )return 0fi
}
complete -F _foo /home/cc/tmp/comp/a.sh
- 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完全正确步骤
- edit
/etc/bash_completion.d/xchencomp
_x_chen_comp()
{local cur prev optsCOMPREPLY=()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
source xchencomp
愉快使用x命令打开qtcreator等软件 ^_^