自制程序安装的 bash-completion 不起作用

自制程序安装的 bash-completion 不起作用

我已经安装了通过自制程序完成 bash并将以下代码添加到.bash_profile

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

尽管有许多有效的 bash 完成脚本,但 Bash 完成不起作用/usr/local/etc/bash_completion.d

$ ls /usr/local/etc/bash_completion.d
abook               mc
adb-completion.bash     mcrypt
ant             mdadm
apache2ctl          medusa
apt             minicom
apt-build           mkinitrd
aptitude            module-init-tools

在 bash 提示符下手动执行 bash-completion 时,出现错误

$ [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
-bash: .: /Users/hanxue/.bash_completion: is a directory
$ source /usr/local/etc/bash_completion
-bash: .: /Users/hanxue/.bash_completion: is a directory

答案1

原来我有一个~/.bash_completion 目录,当 bash-completion 脚本期望文件

删除目录解决了问题,bash-completion 现在可以工作了

$ ls -ld ~/.bash_completion/
drwxr-xr-x  3 hanxue  staff  102 Oct  1  2013 /Users/hanxue/.bash_completion/
$ rm -R ~/.bash_completion
$ [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion

看着bash补全源代码,我找到了这一行

# source user completion file
[[ $BASH_COMPLETION != ~/.bash_completion && -r ~/.bash_completion ]] \
    && . ~/.bash_completion

相关内容