1 # This is startup file for interactive python.
2 # It is not automatically loaded by python interpreter.
3 # To instruct the interpreter to load it insert the following commands
4 # into your .profile (use whatever syntax and initialization file
5 # is appropriate for your shell):
7 # PYTHONSTARTUP=$HOME/init.py # or where you really put it
14 pyreadlinew32_startup = os.path.join(sys.prefix,
15 'lib', 'site-packages', 'pyreadline', 'configuration', 'startup.py')
17 if os.path.exists(pyreadlinew32_startup):
18 execfile(pyreadlinew32_startup)
24 import rlcompleter, readline
25 initfile = os.environ.get('INPUTRC') or os.path.expanduser('~/.inputrc')
26 readline.read_init_file(initfile)
28 histfile = os.path.expanduser('~/.python-history')
30 readline.read_history_file(histfile)
35 histfilesize = os.environ.get('HISTFILESIZE') or \
36 os.environ.get('HISTSIZE')
39 histfilesize = int(histfilesize)
43 readline.set_history_length(histfilesize)
44 readline.write_history_file(histfile)
47 atexit.register(savehist)
49 except (ImportError, AttributeError):
50 pass # no readline or atexit, or readline doesn't have
51 # {read,write}_history_file - ignore the error
54 term = os.environ.get('TERM', '')
58 background = os.environ.get('BACKGROUND', 'light').lower()
62 for _term in ['linux', 'rxvt', 'screen', 'term', 'vt100']:
66 if background == 'dark':
67 ps1_color = '3' # yellow
68 stdout_color = '7' # bold white
70 ps1_color = '4' # blue
71 stdout_color = '0' # bold black
73 sys.ps1 = '\001\033[3%sm\002>>>\001\033[0m\002 ' % ps1_color
74 sys.ps2 = '\001\033[1;32m\002...\001\033[0m\002 ' # bold green
80 def __init__(self, fp, begin, end='\033[0m'): # reset all attributes
86 self.__fp.write(self.__begin+s+self.__end)
88 def writelines(self, lines):
89 map(self.write, lines)
91 def __getattr__(self, attr):
92 return getattr(self.__fp, attr)
94 sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color)
95 sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red
102 pass # locale was not compiled
105 locale.setlocale(locale.LC_ALL, '')
107 from pprint import pprint
109 def displayhook(value):
110 if value is not None:
111 __builtin__._ = value
114 sys.displayhook = displayhook
116 except (ImportError, locale.Error):
117 pass # no locale support or unsupported locale
120 # From: Paul Magwene with a lot of my fixes
123 def __getitem__(self, key):
124 s = os.listdir(os.curdir)
127 def __getslice__(self, i, j):
128 s = os.listdir(os.curdir)
132 return str(os.listdir(os.curdir))
134 def __call__(self, path=None):
136 path = os.path.expanduser(os.path.expandvars(path))
139 return os.listdir(path)
146 def __call__(self, path=None):
147 path = os.path.expanduser(os.path.expandvars(path or '~'))
150 __builtin__.ls = DirLister()
151 __builtin__.cd = DirChanger()
160 #sys.excepthook = info
170 __builtin__.pwd = Pwd()
177 def __call__(self, msg=None):
180 __builtin__.x = _Exit()
182 if isinstance(__builtin__.exit, str): # In Python 2.5+ exit and quit are objects
183 __builtin__.exit = __builtin__.quit = x