bash completion random characters

808 views Asked by At

I am having trouble with bash_completion. When I expand variables, I am fine, but when I use a commands completion (such as git or vim-addon-manager), then the completion throws random characters in there. This didn't use to happen to me, I can't figure out what it is.

This is an example of what happens when I type gitTabTaby

[11:11] me@my_computer:~ $ git
Display all 131 possibilities? (y or n)
^[[01;31m^[[K                    c^[[m^[[Kheckout                 delete-tag                       f^[[m^[[Kmt-merge-msg            i^[[m^[[Knit-db                  notes                            rm
a^[[m^[[Kdd                      c^[[m^[[Kheckout-index           d^[[m^[[Kaemon                   f^[[m^[[Kor-each-ref             i^[[m^[[Knstaweb                 obliterate                       setup
a^[[m^[[Klias                    c^[[m^[[Kheck-ref-format         d^[[m^[[Kelete-branch            f^[[m^[[Kormat-patch             info                             p4                               shortlog
a^[[m^[[Km                       c^[[m^[[Kherry                   d^[[m^[[Kelete-merged-branches   f^[[m^[[Ksck                     line-summary                     pull                             show
a^[[m^[[Knnotate                 c^[[m^[[Kherry-pick              d^[[m^[[Kelete-submodule         f^[[m^[[Ksck-objects             l^[[m^[[Kog                      pull-request                     show-branch
a^[[m^[[Kpply                    c^[[m^[[Klean                    d^[[m^[[Kescribe                 fresh-branch                     l^[[m^[[Ks-files                 push                             show-tree
a^[[m^[[Krchive                  c^[[m^[[Klone                    d^[[m^[[Kiff                     g^[[m^[[Kc                       l^[[m^[[Ks-remote                rebase                           squash
a^[[m^[[Krchive-file             c^[[m^[[Kolumn                   d^[[m^[[Kiff-files               g^[[m^[[Ket-tar-commit-id        l^[[m^[[Ks-tree                  refactor                         stage
b^[[m^[[Kack                     c^[[m^[[Kommit                   d^[[m^[[Kiff-index               g^[[m^[[Krep                     local-commits                    reflog                           stash
b^[[m^[[Kisect                   c^[[m^[[Kommits-since            d^[[m^[[Kifftool                 graft                            mergetool                        release                          status
b^[[m^[[Klame                    c^[[m^[[Kommit-tree              d^[[m^[[Kiff-tree                h^[[m^[[Kash-object              m^[[m^[[Kailinfo                 relink                           submodule
b^[[m^[[Kranch                   c^[[m^[[Konfig                   effort                           h^[[m^[[Kelp                     m^[[m^[[Kailsplit                remote                           subtree
b^[[m^[[Kug                      c^[[m^[[Kontrib                  extras                           h^[[m^[[Kttp-backend             m^[[m^[[Kerge                    rename-tag                       summary
b^[[m^[[Kundle                   c^[[m^[[Kount                    feature                          h^[[m^[[Kttp-fetch               m^[[m^[[Kerge-base               repack                           tag
c^[[m^[[Kat-file                 c^[[m^[[Kount-objects            f^[[m^[[Kast-export              h^[[m^[[Kttp-push                m^[[m^[[Kerge-file               repl                             touch
c^[[m^[[Khangelog                c^[[m^[[Kreate-branch            f^[[m^[[Kast-import              ignore                           m^[[m^[[Kerge-index              replace                          undo
c^[[m^[[Kheck-attr               c^[[m^[[Kredential               f^[[m^[[Ketch                    i^[[m^[[Kmap-send                m^[[m^[[Kerge-octopus            request-pull                     whatchanged
c^[[m^[[Kheck-ignore             c^[[m^[[Kredential-cache         f^[[m^[[Ketch-pack               i^[[m^[[Kndex-pack               mv                               reset
c^[[m^[[Kheck-mailmap            c^[[m^[[Kredential-store         f^[[m^[[Kilter-branch            i^[[m^[[Knit                     name-rev                         revert


Another example is vam tetris (vam tetTabTab):

^[[01;31m^[[Kaddon:  tet^[[m^[[Kris


For vam install tetTabTab, it actually renders it an invalid argument (it's also quite difficult to read), so how can I fix this?

2

There are 2 answers

5
dylnmc On

Apparently, bash completions don't like when grep is colored. Anything like

alias grep='grep --color=always'
alias fgrep='fgrep --color=always'
alias egrep='egrep --color=always'

will give you problems.

Therefore, as Garrett Bellomy details below, it may be wise to use --color=auto, which can be achieved by setting GREP_OPTIONS (or by aliasing grep in your rc file). If you want to make this a global variable, add this to ~/.bash_profile (for bash) or ~/.zprofile (zsh) depending on your default shell: export GREP_OPTIONS='--color=auto'

1
Garrett Bellomy On

I was experiencing the same problem and saw your answer and changed:

export GREP_OPTIONS='--color=always'
to
export GREP_OPTIONS='--color=auto'
This seems to have fixed the problem with bash-completion on my Mac.