1

So I have a custom LS_COLORS setup, and in that I have the following:

mi=05;01;33:
or=05;01;33:

mi is for missing files on the right column when in ls's list view, and or is for a missing files in normal ls mode, or on the left in list mode. The above sets it so that both flash in bright yellow. I set it like that because I thought having it flash would be the most obvious way to alert myself to a missing link, which works great.

But the problem is when I run the python in interactive mode and ask for tab completion, e.g. import re then re.[tab key]. Instead of just getting a normal list whatever is in mi in LS_COLORS gets applied to the suggestions. So I end up with a screen full of blinking text which makes it borderline impossible to read at any reasonable rate.

The same thing happens when I use tab completion in the postgresql interactive mode console. Exactly the same as python. Most other programs or similar are fine though, and bash completion is fine.

Are these programs using ls to format their output? I've currently just changed mi back to something else to get around the problem, and it doesn't really matter because I can still see broken links via or. But I'd be really curious to know why this is happening and if I can stop it.

1

GNU readline is being used, as can be confirmed by listing the default modules:

$ python3
>>> import sys
>>> sys.modules.keys()
dict_keys([...,'readline', 'atexit', 'rlcompleter'])

Readline, by its turn, uses LS_COLORS. From man 3 readline,

colored-stats (Off)
If set to On, readline displays possible completions using different colors to indicate their file type. The color definitions are taken from the value of the LS_COLORS environment variable.

If you are not convinced, go back to the interactive python session and type

>>> a<TAB><TAB>
abs(     all(     and      any(     as       ascii(   assert   async    await
>>> import readline
>>> readline.parse_and_bind("set colored-stats off")
>>> a<TAB><TAB>
abs(     all(     and      any(     as       ascii(   assert   async    await

After disabling colored-stats, the suggested completions (bs(, ll(, etc.) should be on normal color of the terminal. The prefix a still inherits color from LS_COLORS and you can likewise disable it with

readline.parse_and_bind("set colored-completion-prefix off")
2
  • 1
    Oh cool information. Thanks. I think it's probably easier and will work across multiple programs if I just remove 05 from mi then.
    – Levi H
    Aug 19 '20 at 13:09
  • @LeviH Glad to help. Yeah, I think that is the best solution, but it should well be possible to set some kind of .pythonrc that runs a series of commands before starting the interactive session. See in man python3 PYTHONSTARTUP variable.
    – Quasímodo
    Aug 19 '20 at 13:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.