python:colorization_and_tab_completion_for_the_python_shell
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | python:colorization_and_tab_completion_for_the_python_shell [2012/08/14 21:20] (current) – created tkbletsc | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Make a '' | ||
+ | < | ||
+ | # Python startup environment -- color prompt and tab completion | ||
+ | # 2012-08-14 | ||
+ | import sys,os,re | ||
+ | import itertools | ||
+ | |||
+ | if sys.stdout.isatty(): | ||
+ | try: | ||
+ | import readline | ||
+ | except ImportError: | ||
+ | print " | ||
+ | else: | ||
+ | import rlcompleter | ||
+ | readline.parse_and_bind(" | ||
+ | |||
+ | # ANSI coloring with readline escape codes | ||
+ | def c(s='' | ||
+ | |||
+ | if os.environ.get(' | ||
+ | sys.ps1 = c(' | ||
+ | sys.ps2 = c(' | ||
+ | |||
+ | def displayhook(v): | ||
+ | sys.stdout.write(' | ||
+ | sys.__displayhook__(v) | ||
+ | sys.stdout.write(' | ||
+ | sys.displayhook = displayhook | ||
+ | del displayhook | ||
+ | |||
+ | def excepthook(type, | ||
+ | sys.stdout.write(' | ||
+ | sys.__excepthook__(type, | ||
+ | sys.stdout.write(' | ||
+ | sys.excepthook = excepthook | ||
+ | del excepthook | ||
+ | |||
+ | sys.stderr.write(c(' | ||
+ | |||
+ | del c | ||
+ | </ | ||
+ | |||
+ | Set environment variable to enable it: | ||
+ | PYTHONSTARTUP=$HOME/ | ||
+ | |||
+ | That's all. |
python/colorization_and_tab_completion_for_the_python_shell.txt · Last modified: 2012/08/14 21:20 by tkbletsc