一个脚本中的多个自动完成函数



我有一个命令pyseqtools.py,我想为位置参数和标志(-a/--analysis)启用自动完成。我可以在单独的自动完成脚本中使用以下代码行分别自动完成它们中的任何一个:

stat_list="mageck bagel2"
function analysis()
{
case $3 in
-a) COMPREPLY=($(compgen -W "$stat_list" "${COMP_WORDS[$COMP_CWORD]}"));;
--analysis) COMPREPLY=($(compgen -W "$stat_list" "${COMP_WORDS[$COMP_CWORD]}"));;
esac
}
complete -F analysis pyseqtools.py

module()
{
local opts
opts="crispr rna-seq chip-seq cutrun"
case $COMP_CWORD in
1)
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
;;
esac
return 0
}
complete -F module pyseqtools.py 

当我将所有代码放在一个自动完成脚本中时,只有文件底部的代码块在工作。我怎么能使他们都在一个脚本工作?

我通过将两个函数合并为一个来使其工作:

stat_list="mageck bagel2"
function _complete()
{
case $3 in
-a) COMPREPLY=($(compgen -W "$stat_list" "${COMP_WORDS[$COMP_CWORD]}"));;
--analysis) COMPREPLY=($(compgen -W "$stat_list" "${COMP_WORDS[$COMP_CWORD]}"));;
esac
local opts
opts="crispr rna-seq chip-seq cutrun"
case $COMP_CWORD in
1)
COMPREPLY=( $(compgen -W "${opts}" -- "${COMP_WORDS[COMP_CWORD]}") )
;;
esac
return 0
}
complete -F _complete pyseqtools.py

最新更新