Strange characters in GIT completion

xx77aBs

I'm running bash

GNU bash, version 4.3.25(1)-release (x86_64-apple-darwin13.4.0)

on OS X 10.10.1. A week or so ago I've noticed that autocompletion has stopped working, but only for git. I'm using this script for git autocompletion:

https://github.com/git/git/blob/master/contrib/completion/git-completion.bash

Few days after it has stopped working, I've noticed that autocompletion still works for commands starting with letter 's' (e.g. status, show, stash). After that I've tried to autocomplete this command:

git c

and here's the output:

user:~$ git c^[[m^[[K

c^[[m^[[Kat-file
c^[[m^[[Kheck-attr
c^[[m^[[Kheck-ignore
c^[[m^[[Kheck-mailmap
c^[[m^[[Kheck-ref-format
c^[[m^[[Kheckout
c^[[m^[[Kheckout-index
c^[[m^[[Kherry
c^[[m^[[Kherry-pick
c^[[m^[[Kitool
c^[[m^[[Klean
c^[[m^[[Klone
c^[[m^[[Kolumn
c^[[m^[[Kommit
c^[[m^[[Kommit-tree
c^[[m^[[Konfig
c^[[m^[[Kount-objects
c^[[m^[[Kredential
c^[[m^[[Kredential-cache
c^[[m^[[Kredential-osxkeychain
c^[[m^[[Kredential-store
c^[[m^[[Kvsexportcommit
c^[[m^[[Kvsimport
c^[[m^[[Kvsserver

As you can see, some strange (escape?) characters are inserted after the first letter of each command (the same happens for all other letters other than 's'). Because of those characters, autocompletion isn't working as expected.

Does anyone have an idea of what could cause this? I do not even know how to debug this, so any tips are welcome.

Gilles 'SO- stop being evil'

These strange escape sequences are color-changing commands.

The completion code runs the following command to list available commands:

git help -a|egrep '^  [a-zA-Z0-9]'

The output of git help -a looks like this:

add grep remote add--interactive hash-object remote-ext am help remote-fd … fsck-objects receive-pack write-tree gc reflog get-tar-commit-id relink

If grep is configured to print the matching part of the line in color, then command names that are in the first column will have their first letter highlighted:

$ git help -a|egrep --color=always '^  [a-zA-Z0-9]' | cat -v | head -n 1
^[[01;31m^[[K  a^[[m^[[Kdd                      grep                     remote

When bash sees this output, it thinks that ^[[01;31m^[[K, a^[[m^[[Kdd, grep and remote are possible commands. The first one won't turn up, the last two are correct, the second one is mangled.

You need to configure grep not to use colors when its output is not on a terminal. If you've aliased egrep to egrep --color=always (and ditto for grep and fgrep), change that to --color=auto. If you've set the GREP_OPTIONS variable somewhere, change --color=always to --color=auto there.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related