Bash 将帮助样式信息编入完成方法

Bash 将帮助样式信息编入完成方法,bash,tab-completion,bash-completion,Bash,Tab Completion,Bash Completion,我有一个方法,当您在没有选项的情况下运行它时,可以解释它的用法: Usage: SQLbatch [database] [file] [maximum # of lines in batch] [time to sleep between batches] [who to email when finished] 最近,我在业余时间写了一个制表符完成脚本: _SQLbatch() { local cur dbs COMPREPLY=() dbs=$(< /...di

我有一个方法,当您在没有选项的情况下运行它时,可以解释它的用法:

Usage:
SQLbatch [database] [file] [maximum # of lines in batch] [time to sleep between batches] [who to email when finished]
最近,我在业余时间写了一个制表符完成脚本:

_SQLbatch()
{    

  local cur dbs
  COMPREPLY=()
  dbs=$(< /...directory paths.../allDbs.txt)
  cur="${COMP_WORDS[COMP_CWORD]}"

  case "$COMP_CWORD" in
  1)
     case "$cur" in
     *@*)   
        COMPREPLY=( $(compgen -W "$dbs" -- "$cur" | sed -e "s/.*@/@/") )
        return 0    
        ;;          
     *)   
        COMPREPLY=( $(compgen -W "$dbs" -- "$cur") )
        return 0    
        ;;          
     esac   
     ;;     
  2)
     COMPREPLY=( $(compgen -f -- "$cur") )
     return 0
     ;;     
  *)
  esac
}    

complete -F _SQLbatch SQLbatch
我想提醒用户他们还需要什么,而不破坏他们已经输入的内容。我最近的方法是这样的:

...
  *)
     echo -e "\nSQLbatch [database] [file] [maximum # of lines in batch] [time to sleep between batches] [who to email when finished]"
     return 0
     ;;
  esac
...

这几乎可以做到,但最终无法在最新一行重新显示用户输入。有没有办法迫使这最后一步完成呢?

以下是你的方法。我们要做的是生成PS1(shell提示符)和您当前的单词来修复断开的新行。我们可以将
$actualPS1
的内容直接粘贴到echo语句中,但我认为这种方法更清晰

...
*)
    actualPS1=$(eval echo \"$PS1\")
    echo -en "\nWhatever line of text you want.\n"
    echo -en "${actualPS1}${COMP_WORDS[@]}"
    return 0
    ;;
esac
...
这将为您的具体案例打印一行文本,然后将控制台正确地返回给您。没有必要指定COMPREPLY应该是什么

请注意,您基本上可以将此完成添加到任何无法通过正常方式完成的内容中,作为对最终用户的有用提醒。一种可能使用这种方法的方法是
echo
本身

...
*)
    actualPS1=$(eval echo \"$PS1\")
    echo -en "\nWhatever line of text you want.\n"
    echo -en "${actualPS1}${COMP_WORDS[@]}"
    return 0
    ;;
esac
...