我正在为一些包装脚本编写一个设置文件,并将这些脚本映射到底层命令的完成。
在我的 .bash_profile 中,这会将 git 的完成映射到 git_wrapper:
complete -F _git git_wrapper
在我的 setup.sh 中,以下内容不起作用,因为脚本不是交互式的(type _git
失败,因为_git
在非交互式 shell 中不可用):
if type _git &>/dev/null && ! grep "complete.*_git git_wrapper" ~/.bash_profile &>/dev/null ; then
echo "complete -F _git git_wrapper" >> ~/.bash_profile
fi
在 setup.sh 中,如何检查 _git 补全是否可用于交互式 shell?