Bash无法在/opt/local/etc/bash_completion.d/运行脚本


8

我想对git命令使用bash自动补全功能,因此我将bash脚本文件放入/opt/local/etc/bash_completion.d/

当我打开一个新的终端时,/opt/local/etc/bash_completion.d/不会执行脚本文件。我已经通过运行验证了脚本文件是否正常工作:

source /opt/local/etc/bash_completion.d/git-completion.bash

是否缺少任何步骤要求OS X自动执行脚本/opt/local/etc/bash_completion.d/

Answers:


8

为了自动从目录加载所有脚本,请将其放入~/.bashrc文件中

# LOAD ALL AUTOCOMPLETIONS IF ANY ARE INSTALLED
if [ -d /usr/local/etc/bash_completion.d ]; then
    for F in "/usr/local/etc/bash_completion.d/"*; do
        if [ -f "${F}" ]; then
            source "${F}";
        fi
    done
fi

3

是的,您需要将它们加载到您的外壳中。

这是通过编辑~/.bashrc~/.bash_profile添加. filename每个文件的命令来完成的。这将加载文件并使功能可用。即将您的源代码命令放在这些文件之一中。

请注意,您不应添加到,/opt/local/etc/bash_completion.d/因为只有macports才能在其中写入。将文件放在您的主目录中,例如~/.bash_completion.d/git-completion.bash

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.