参数中路径的重击完成(存在等号) [英] Bash completion for path in argument (with equals sign present)

查看:77
本文介绍了参数中路径的重击完成(存在等号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前可以键入以下内容:

I used to be able to type the following:

$> ./foo --arg =< TAB>

$> ./foo --arg=<TAB>

在foo是我编写的任何程序,它会给我当前目录中的文件列表,就像通常使用tab-completion一样.我不必对/etc/bash_completion进行任何更改.

Where foo is any program I wrote, and it would give me a list of files in the current directory, just like tab-completion normally does. I didn't have to make any changes to /etc/bash_completion.

但是,最近,由于某种未知的原因,这种现象已经消失了.有人知道如何重新启用此功能吗?

Recently, however, this has gone away for some unknown reason. Does anyone know how to re-enable this feature?

FWIW,这仍然是正确的事情(注意缺少等号):

FWIW, this still does the correct thing (notice the lack of an equals sign):

$> ./foo --arg< TAB>

$> ./foo --arg <TAB>

推荐答案

我删除了所有bash补全脚本,并开始将它们逐个添加,以防它们引起问题.

I removed all bash completion scripts and started adding them one by one to if any of them cause the problem.

在我看来,npm完成脚本是导致此问题的原因.

In my case it turned out to be the npm completion script was the cause of this problem.

不确定(尚未)是什么问题,但这是导致等号值无法像以前那样工作的完成脚本:

Not sure (yet) what the problem is, but this is the completion script which caused equal sign values not working as before:

    ###-begin-npm-completion-###
    #
    # npm command completion script
    #
    # Installation: npm completion >> ~/.bashrc  (or ~/.zshrc)
    # Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
    #

    COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
    COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
    export COMP_WORDBREAKS

    if type complete &>/dev/null; then
      _npm_completion () {
        local si="$IFS"
        IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
                               COMP_LINE="$COMP_LINE" \
                               COMP_POINT="$COMP_POINT" \
                               npm completion -- "${COMP_WORDS[@]}" \
                               2>/dev/null)) || return $?
        IFS="$si"
      }
      complete -F _npm_completion npm
    elif type compdef &>/dev/null; then
      _npm_completion() {
        si=$IFS
        compadd -- $(COMP_CWORD=$((CURRENT-1)) \
                     COMP_LINE=$BUFFER \
                     COMP_POINT=0 \
                     npm completion -- "${words[@]}" \
                     2>/dev/null)
        IFS=$si
      }
      compdef _npm_completion npm
    elif type compctl &>/dev/null; then
      _npm_completion () {
        local cword line point words si
        read -Ac words
        read -cn cword
        let cword-=1
        read -l line
        read -ln point
        si="$IFS"
        IFS=$'\n' reply=($(COMP_CWORD="$cword" \
                           COMP_LINE="$line" \
                           COMP_POINT="$point" \
                           npm completion -- "${words[@]}" \
                           2>/dev/null)) || return $?
        IFS="$si"
      }
      compctl -K _npm_completion npm
    fi
    ###-end-npm-completion-###

这篇关于参数中路径的重击完成(存在等号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆