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', 'term', 'rxvt', 'vt100', 'screen']:
64 if background == 'dark':
65 ps1_color = '3' # yellow
66 stdout_color = '7' # bold white
68 ps1_color = '4' # blue
69 stdout_color = '0' # bold black
71 sys.ps1 = '\001\033[3%sm\002>>>\001\033[0m\002 ' % ps1_color
72 sys.ps2 = '\001\033[1;32m\002...\001\033[0m\002 ' # bold green
78 def __init__(self, fp, begin, end='\033[0m'): # reset all attributes
84 self.__fp.write(self.__begin+s+self.__end)
86 def writelines(self, lines):
87 map(self.write, lines)
89 def __getattr__(self, attr):
90 return getattr(self.__fp, attr)
92 sys.stdout = ColoredFile(sys.stdout, '\033[1;3%sm' % stdout_color)
93 sys.stderr = ColoredFile(sys.stderr, '\033[31m') # red
100 pass # locale was not compiled
103 locale.setlocale(locale.LC_ALL, '')
105 from pprint import pprint
107 def displayhook(value):
108 if value is not None:
109 __builtin__._ = value
112 sys.displayhook = displayhook
114 except (ImportError, locale.Error):
115 pass # no locale support or unsupported locale
118 # From: Paul Magwene with a lot of my fixes
121 def __getitem__(self, key):
122 s = os.listdir(os.curdir)
125 def __getslice__(self, i, j):
126 s = os.listdir(os.curdir)
130 return str(os.listdir(os.curdir))
132 def __call__(self, path=None):
134 path = os.path.expanduser(os.path.expandvars(path))
137 return os.listdir(path)
144 def __call__(self, path=None):
145 path = os.path.expanduser(os.path.expandvars(path or '~'))
148 __builtin__.ls = DirLister()
149 __builtin__.cd = DirChanger()
158 #sys.excepthook = info
168 __builtin__.pwd = Pwd()
175 def __call__(self, msg=None):
178 __builtin__.x = _Exit()
180 if isinstance(__builtin__.exit, str): # In Python 2.5+ exit and quit are objects
181 __builtin__.exit = __builtin__.quit = x