2

I use bash completion from https://bash-completion.alioth.debian.org/ and some vendor supplied scripts too (eg. https://github.com/git/git/blob/master/contrib/completion/git-completion.bash)

I also use export GREP_OPTIONS='-I --color=always --exclude=*.xhprof' because setting --color=always in (almost) every pipe is a massive pain.

However the completion scripts often use grep and don't specify --color=auto or --color=never because by default it's not needed, this leads to broken output where escaped terminal color codes get interleaved with the output making it hard to read. (see below)

^[[01;31m^[[K                    c^[[m^[[Kherry                   d^[[m^[[Kescribe                 g^[[m^[[Krep                     m^[[m^[[Kailinfo                 request-pull 
a^[[m^[[Kdd                      c^[[m^[[Kherry-pick              d^[[m^[[Kiff                     g^[[m^[[Kui                      m^[[m^[[Kailsplit                reset 
a^[[m^[[Km                       c^[[m^[[Kitool                   d^[[m^[[Kiff-files               h^[[m^[[Kash-object              m^[[m^[[Kerge                    revert 
a^[[m^[[Knnotate                 c^[[m^[[Klean                    d^[[m^[[Kiff-index               h^[[m^[[Kelp                     m^[[m^[[Kerge-base               rm 
a^[[m^[[Kpply                    c^[[m^[[Klone                    d^[[m^[[Kiff-tree                h^[[m^[[Kttp-backend             m^[[m^[[Kerge-file               send-email 
a^[[m^[[Krchimport               c^[[m^[[Kolumn                   d^[[m^[[Kifftool                 h^[[m^[[Kttp-fetch               mergetool                        shortlog 
a^[[m^[[Krchive                  c^[[m^[[Kommit                   f^[[m^[[Kast-export              h^[[m^[[Kttp-push                mv                               show 
b^[[m^[[Kisect                   c^[[m^[[Kommit-tree              f^[[m^[[Kast-import              history                          name-rev                         show-branch 
b^[[m^[[Klame                    c^[[m^[[Konfig                   f^[[m^[[Ketch                    i^[[m^[[Kndex-pack               notes                            stage 
b^[[m^[[Kranch                   c^[[m^[[Kount-objects            f^[[m^[[Ketch-pack               i^[[m^[[Knit                     p4                               stash 
b^[[m^[[Kundle                   c^[[m^[[Kredential               f^[[m^[[Kilter-branch            i^[[m^[[Knit-db                  pull                             status 
c^[[m^[[Kat-file                 c^[[m^[[Kredential-cache         f^[[m^[[Kmt-merge-msg            i^[[m^[[Knstaweb                 push                             submodule 
c^[[m^[[Kheck-attr               c^[[m^[[Kredential-osxkeychain   f^[[m^[[Kor-each-ref             i^[[m^[[Knterpret-trailers       rebase                           subtree 
c^[[m^[[Kheck-ignore             c^[[m^[[Kredential-store         f^[[m^[[Kormat-patch             l^[[m^[[Kog                      reflog                           svn 
c^[[m^[[Kheck-mailmap            c^[[m^[[Kvsexportcommit          f^[[m^[[Ksck                     l^[[m^[[Ks-files                 relink                           tag 
c^[[m^[[Kheck-ref-format         c^[[m^[[Kvsimport                f^[[m^[[Ksck-objects             l^[[m^[[Ks-remote                remote                           verify-commit 
c^[[m^[[Kheckout                 c^[[m^[[Kvsserver                g^[[m^[[Kc                       l^[[m^[[Ks-tree                  repack                           whatchanged 
c^[[m^[[Kheckout-index           d^[[m^[[Kaemon                   g^[[m^[[Ket-tar-commit-id        lg                               replace                          worktree 

If completion were a command I ran manually I could just prepend the command with GREP_OPTIONS="", but since it's some combination of readline and bash which I don't fully understand I don't know what to do.

So is there a way to clear the GREP_OPTIONS during tab completion? Or some other solution that doesn't involve me typing --color=always over 100 times a day?

  • 1
    Why don't you alias grep to grep --color=always? Setting GREP_OPTIONS is risky. It's not only completion scripts that are affected. – muru Jan 3 '16 at 22:28
  • I used to have grep aliased, but it broke far more things than GREP_OPTIONS has since I switched. That forum post says that aliases don't affect scripts, but I've found that to be false. – Camden Narzt Jan 3 '16 at 22:30
  • I find that unbelievable, since GREP_OPTIONS affects every instance of grep, but aliases only affect your interactive shell. For aliases to affect scripts, the script has to enable them. And if a script does enable them, then it has no way of knowing what it's running. – muru Jan 3 '16 at 22:37
  • I just tried switching to an alias as you suggested and it didn't solve the problem I described in my question. So there's that too. – Camden Narzt Jan 3 '16 at 22:56
  • Yes, and I created a new terminal, with a new bash session, and checked with echo $GREP_OPTIONS that it was indeed unset. – Camden Narzt Jan 3 '16 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.