From 124c81f0b2852c2517bb2f616ef7bd2b1f9c3ee1 2008-01-11 07:03:11 From: vivainio Date: 2008-01-11 07:03:11 Subject: [PATCH] add autoexec option --- diff --git a/IPython/UserConfig/ipy_user_conf.py b/IPython/UserConfig/ipy_user_conf.py index f5054a3..33d158b 100644 --- a/IPython/UserConfig/ipy_user_conf.py +++ b/IPython/UserConfig/ipy_user_conf.py @@ -26,17 +26,12 @@ ip = IPython.ipapi.get() import os -def main(): - # Handy tab-completers for %cd, %run, import etc. - # Try commenting this out if you have completion problems/slowness - # import ipy_stock_completers - +def main(): + # uncomment if you want to get ipython -p sh behaviour - # without having to use command line switches - + # without having to use command line switches # import ipy_profile_sh - # Configure your favourite editor? # Good idea e.g. for %edit os.path.isfile @@ -62,13 +57,22 @@ def main(): #import_all("os sys") #execf('~/_ipython/ns.py') + + # -- prompt # A different, more compact set of prompts from the default ones, that # always show your current location in the filesystem: - + #o.prompt_in1 = r'\C_LightBlue[\C_LightCyan\Y2\C_LightBlue]\C_Normal\n\C_Green|\#>' #o.prompt_in2 = r'.\D: ' #o.prompt_out = r'[\#] ' - + + # Try one of these color settings if you can't read the text easily + # autoexec is a list of IPython commands to execute on startup + #o.autoexec.append('%colors LightBG') + #o.autoexec.append('%colors NoColor') + #o.autoexec.append('%colors Linux') + + # some config helper functions you can use def import_all(modules): """ Usage: import_all("os sys") """ diff --git a/IPython/iplib.py b/IPython/iplib.py index 3287910..8e20637 100644 --- a/IPython/iplib.py +++ b/IPython/iplib.py @@ -6,7 +6,7 @@ Requires Python 2.3 or newer. This file contains all the classes and helper functions specific to IPython. -$Id: iplib.py 2919 2007-12-31 14:45:55Z vivainio $ +$Id: iplib.py 2930 2008-01-11 07:03:11Z vivainio $ """ #***************************************************************************** @@ -591,6 +591,7 @@ class InteractiveShell(object,Magic): auto_alias = () self.auto_alias = [s.split(None,1) for s in auto_alias] + # Produce a public API instance self.api = IPython.ipapi.IPApi(self) @@ -601,9 +602,12 @@ class InteractiveShell(object,Magic): self.builtins_added = {} # This method will add the necessary builtins for operation, but # tracking what it did via the builtins_added dict. + + #TODO: remove this, redundant self.add_builtins() + # end __init__ @@ -710,6 +714,10 @@ class InteractiveShell(object,Magic): self.hooks.late_startup_hook() + for cmd in self.rc.autoexec: + #print "autoexec>",cmd #dbg + self.api.runlines(cmd) + batchrun = False for batchfile in [path(arg) for arg in self.rc.args if arg.lower().endswith('.ipy')]: diff --git a/IPython/ipmaker.py b/IPython/ipmaker.py index e0e934b..d281077 100644 --- a/IPython/ipmaker.py +++ b/IPython/ipmaker.py @@ -6,7 +6,7 @@ Requires Python 2.1 or better. This file contains the main make_IPython() starter function. -$Id: ipmaker.py 2913 2007-12-31 12:42:14Z vivainio $""" +$Id: ipmaker.py 2930 2008-01-11 07:03:11Z vivainio $""" #***************************************************************************** # Copyright (C) 2001-2006 Fernando Perez. @@ -190,6 +190,7 @@ object? -> Details about 'object'. ?object also works, ?? prints more. autoedit_syntax = 0, autoindent = 0, automagic = 1, + autoexec = [], banner = 1, c = '', cache_size = 1000, diff --git a/doc/ChangeLog b/doc/ChangeLog index cc2272a..3f6c226 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,12 @@ +2008-01-11 Ville Vainio + + * iplib.py, ipmaker.py: new rc option - autoexec. It's a list + of ipython commands to be run when IPython has started up + (just before running the scripts and -c arg on command line). + + * ipy_user_conf.py: Added an example on how to change term + colors in config file (through using autoexec). + 2008-01-10 Ville Vainio * Prompts.py (set_p_str): do not crash on illegal prompt strings