.pystartup
changeset 270 19082e26bea6
parent 227 d2bb2c3da51b
child 311 a63540742a19
equal deleted inserted replaced
269:48b3cbdac750 270:19082e26bea6
       
     1 # -*- mode: python -*-
       
     2 # Add auto-completion and a stored history file of commands to your Python
       
     3 # interactive interpreter. Requires Python 2.0+, readline. Autocomplete is
       
     4 # bound to the Esc key by default (you can change it - see readline docs).
       
     5 #
       
     6 # Store the file in ~/.pystartup, and set an environment variable to point
       
     7 # to it:  "export PYTHONSTARTUP=~/.pystartup" in bash.
       
     8 
       
     9 import os
       
    10 import sys
       
    11 import atexit
       
    12 import readline
       
    13 import rlcompleter
       
    14 
       
    15 historyPath = os.path.expanduser("~/.pyhistory")
       
    16 
       
    17 def save_history(historyPath=historyPath):
       
    18     import readline
       
    19     readline.write_history_file(historyPath)
       
    20 
       
    21 if os.path.exists(historyPath):
       
    22     readline.read_history_file(historyPath)
       
    23 
       
    24 term_with_colors = ['xterm', 'xterm-color', 'xterm-256color', 'linux', 'screen', 'screen-256color', 'screen-bce']
       
    25 if os.environ.get('TERM') in term_with_colors:
       
    26     green='\033[32m'
       
    27     red='\033[31m'
       
    28     reset='\033[0m'
       
    29     sys.ps1 = red + '>>> ' + reset
       
    30     sys.ps2 = green + '... ' + reset
       
    31 del term_with_colors
       
    32 
       
    33 atexit.register(save_history)
       
    34 del os, sys, atexit, readline, rlcompleter, save_history, historyPath
       
    35