Skip to content

Instantly share code, notes, and snippets.

@jseabold
Last active October 9, 2015 05:07
Show Gist options
  • Save jseabold/3442688 to your computer and use it in GitHub Desktop.
Save jseabold/3442688 to your computer and use it in GitHub Desktop.
ipython default profile config with git branch
c = get_config()
# lines of code to run at IPython startup.
c.TerminalIPythonApp.exec_lines = [
'Exit = exit',
'import numpy as np',
'np.set_printoptions(suppress=True)',
'import statsmodels.api as sm',
'import matplotlib.pyplot as plt',
'from scipy import stats, optimize',
'import sklearn',
'import pandas as pd',
'import patsy',
"""pd.set_printoptions(notebook_repr_html=False,
precision=4,
max_columns=12)""",
"""
from IPython.core.prompts import LazyEvaluate
@LazyEvaluate
def parse_git_branch():
import subprocess
cmd = 'ref=$(git symbolic-ref HEAD 2> /dev/null); echo \"(\"${ref#refs/heads/}\")\"'
branch = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).communicate()[0]
if not branch.strip().strip("()"):
return ""
else:
return branch""",
"""get_ipython().prompt_manager.lazy_evaluate_fields["parse_git_branch"] = parse_git_branch""",
r"get_ipython().prompt_manager.in_template = '[\Y0/] {parse_git_branch}\n[\#]: '"
]
# Set the editor used by IPython (default to $EDITOR/vi/notepad).
c.TerminalInteractiveShell.editor = 'gvim -f'
c.PromptManager.in_template = '[\Y0/]\n[\#]: '
c.PromptManager.out_template = '[\#]: '
c.TerminalInteractiveShell.autocall = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment