2

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?

dylnmc
  • 3,810
  • 4
  • 26
  • 42
  • The problem is not bash. It's your terminal settings. You might want to revise or replace your question. – donjuedo Jun 18 '15 at 20:35
  • @donjuedo My question is simply how to get these from showing up. I searched many places and didn't find this answer. I have tried using konsole, gnome-terminal. rxvt, even ctrl+alt+F1 (in linux). Could it be `~/.Xdefaults`? ... nope; I'm not even using that.... hmm I am at a loss. I honestly think it is bash. – dylnmc Jun 18 '15 at 20:37
  • @donjuedo so, I just install `zsh` and it knows how to complete (git) properly.... except it doesn't have completions for `vam` :/ – dylnmc Jun 18 '15 at 20:40
  • I've tried everything in terms of terminal settings... – dylnmc Jun 18 '15 at 20:44
  • 1
    In your shoes, I'd meld (diff with a GUI) the bashrc file you mentioned with that of a co-worker or buddy nearby. You also might find differences in the environment variables (`set > envvars.txt` for example) and meld some more. I'd volunteer to be that guy, but I'm planted in front of a Windows machine for another couple of hours. – donjuedo Jun 18 '15 at 20:45
  • 1
    @donjuedo Ah; good idea. I did discover, it is in fact my bashrc. I just did `mv ~/.bashrc ~/.bashrc~` and then restarted my terminal, and git works fine. The question, now, is what line is giving me the problem... time to start commenting some stuff. Maybe I'll even find a bug. I know pretty much what everything in the bashrc does... there *shouldn't* be any problems. – dylnmc Jun 18 '15 at 20:48
  • @donjuedo I found it! Bash completions apparently don't like `grep` to be colored; so, `alias grep='grep --color=always'`, `alias fgrep='fgrep --color=always'`, and `alias egrep='egrep --color=always'` give me problems. Well... – dylnmc Jun 18 '15 at 20:51
  • I am impressed. I had no idea auto completion used grep under the hood and presented some output from it. Good to know. – donjuedo Jun 18 '15 at 20:53
  • @donjuedo AH! When I do `vam install tet`Tab Tab.... it still happens... but everythin else works. – dylnmc Jun 18 '15 at 21:04
  • Ha! I was just running an older instance of my terminal... It has, in fact, been fixed. Sorry – dylnmc Jun 18 '15 at 21:05

2 Answers2

1

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'

dylnmc
  • 3,810
  • 4
  • 26
  • 42
  • I usually use `--color=auto` for commands that support colors. – pynexj Jun 19 '15 at 01:31
  • @whjm Yeah; that does work for bash completion. I thought I might have had a reason for doing always, but I can't remember whatsoever. Good idea! – dylnmc Jun 19 '15 at 23:14
  • Sometimes I also have a reason to use `always`. E.g.: `grep foo /some/files | less` – pynexj Jun 20 '15 at 00:26
  • huh. Why would you want always with that? Wouldn't that give you like `Esc[...m` a bunch of times with less? If so/if not, when would you use `always`? – dylnmc Jun 20 '15 at 01:21
  • `less -r`: Causes "*raw*" control characters to be displayed. `less -R`: Like `-r`, but only ANSI "*color*" escape sequences are output in "*raw*" form. – pynexj Jun 20 '15 at 13:51
1

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.
  • Nice thought! I run linux, but anyone can put `export GREP_OPTIONS='--color=auto'` in your `~/.bash_profile` (if you run *bash*, *sh*, most shells) or `~/.zprofile` if you run *zsh* as primary shell. Additionally, this could be put in `~/.bashrc` or your shell's *rc* file; however, I tend to put global variables like this in my profile. – dylnmc Apr 12 '17 at 17:18