当我想要为位置参数和标志(-a/--analysis)启用自动完成时,我有一个命令pyseqtools.py。我可以在单独的自动完成脚本中使用以下几行代码分别自动完成它们中的任何一个:
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 当我将所有代码放在一个自动完成脚本中时,只有文件底部的代码块可以正常工作。我怎样才能让它们在一个脚本中都能工作?
发布于 2021-08-07 09:48:45
我通过将这两个函数合并为一个函数来使其工作:
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.pyhttps://stackoverflow.com/questions/68589042
复制相似问题