Bash completion for path in argument (with equals sign present)

前端 未结 3 1309
醉酒成梦
醉酒成梦 2021-01-05 05:53

I used to be able to type the following:

$> ./foo --arg=

Where foo is any program I wrote, and it would give me a list of files in the current dir

相关标签:
3条回答
  • 2021-01-05 06:23

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

    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-###
    
    0 讨论(0)
  • 2021-01-05 06:33

    Not sure what environment you're in, but on a recent CentOS

    complete -D -o default
    

    enables filename completion after a token w/o whitespace as the default. To toggle it in the other direction:

    complete -D -o nospace
    

    However, it looks like older versions of the builtin don't have the -D option.

    0 讨论(0)
  • 2021-01-05 06:36

    I resolved the same trouble with Ubuntu 12.04 by using https://github.com/ai/rake-completion. You need to

    1. download the file wget -O ~/scripts/rake https://raw.githubusercontent.com/ai/rake-completion/master/rake
    2. add to your .bashrc: . ~/scripts/rake

    or You can use one of other ways on that page.

    0 讨论(0)
提交回复
热议问题