Bash termination for the path in the argument (if there is an equal sign)

I used to enter the following:

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

Where foo is any program that I wrote, and it will provide me with a list of files in the current directory, as the tab usually does. I did not need to make any changes to / etc / bash _completion.

Recently, however, this has disappeared for an unknown reason. Does anyone know how to enable this feature again?

FWIW, this still does the right thing (note the lack of an equal sign):

$> ./foo --arg <TAB>

+6
source share
3 answers

I deleted all bash completion scripts and started adding them one by one if any of them caused a problem.

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

Not sure (yet) what the problem is, but this is the completion of the script, which led to the fact that equal signed values ​​do not work 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-### 
+7
source

Not sure which environment you're in, but in recent CentOS

 complete -D -o default 

allows the completion of the file name after the character without spaces by default. To switch it in the other direction:

 complete -D -o nospace 

However, it seems that older versions of the built-in functions do not have the -D option.

+1
source

I solved the same problems with Ubuntu 12.04 using https://github.com/ai/rake-completion . You need

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

or you can use one of the other methods on this page.

+1
source

Source: https://habr.com/ru/post/959296/


All Articles