Pash bash完成功能无法在Mac Os X上运行

时间:2014-05-19 22:14:48

标签: macos bash pip bash-completion dotfiles

我在Mac Snow Leopard上,python是从homebrew开始安装的,它有两个自定义bash完成脚本,一个用于pip,另一个用于{{ 1}}。他们过去常常工作,但在弄乱了我的dotfiles之后他们就再也没有工作了。

django 完成来自original projectdjango(来自here)如下所示:

pip completion

错误: Django完成任何时候我都会抛出它:

_pip() {
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    commands=$(pip --help | awk '/Commands\:/,/General Options\:/' | \
               \grep -E -o "^\s{2}\w*" | tr -d ' ')
    opts=$(pip --help | \grep -E -o "((-\w{1}|--(\w|-)*=?)){1,2}")

    if [ $COMP_CWORD == 1 ] ; then
        COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
        return 0
    fi

    if [[ ${cur} == -* ]] ; then
        local command_opts=$(pip $prev --help | \
                             \grep -E -o "((-\w{1}|--(\w|-)*=?)){1,2}")
        COMPREPLY=( $(compgen -W "${command_opts}" -- ${cur}) )
        return 0
    fi
}

complete -o default -F _pip pip

所以基本上它应该是一个语法问题。我complete: usage: complete [-abcdefgjksuv] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] pip completion无效。

重点是他们都曾经工作但我不知道会发生什么。 据我所知,pip + TAB函数是内置的bash,我没有搞砸bash,只有dotfiles ..有线索?

1 个答案:

答案 0 :(得分:0)

事实证明,这与某些命令的Apple实现与GNU / BSD命令有关。

我确实通过安装brew:

中的grep解决了pip完成问题
brew install grep --default-names

这将在/ usr / local / bin / grep下安装GNU grep--default-names表示它将被称为grep而不是ggrep/usr/local/bin 1}}位于$PATH之前的/bin/usr/bin,它优先于grep的苹果版本。

对于django completion,问题来自whereis命令:

unset pythons
if command -v whereis &>/dev/null; then
    python_interpreters=$(whereis python | cut -d " " -f 2-)
    for python in $python_interpreters; do
        pythons="${pythons} ${python##*/}"
    done
    pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
else
    pythons=python
fi
complete -F _python_django_completion -o default $pythons

我搞砸了python,而/usr/bin/python指的是一个旧的安装,不再存在了。我已修复链接(在我的情况下)指向从brew安装的python,一切正常。

相关问题