# IPython Shell Integration

This post shows you how to take IPython’s sweet bash/shell integration to another level. Of particular interest is my last example, which utilizes IPython’s syntax and bash integration to create a scripting language that supports pure Python + IPython features + bash (as supported by IPython).

##### First off, some distinctions: IPython has aliases, macros, and magics. They are different things.
• Aliases are shortcuts to bash commands that get piped out to the os in a subprocess. One alias is a tuple. ie. (“showmydirectory”, “ls”).
• Macros are shortcuts to python code stored as a string. They are editable via the ‘%edit’ magic command
• Magics are functions special to IPython that take parameters and utilize IPython internals to do helpful things. They can be identified by the ‘%’ at the beginning.
##### On to some code:
1.  Import everything within your path that is executable as an IPython alias. This means you can use bash commands like ‘git status’ or ‘tail -f somefilename grep something’ without explicitly using the ‘!’ to define a bash command.
1. Define an IPython alias within the IPython Interpreter.
1. Profile Customization: Automatically port bash aliases and run the magic, %rehashx, on startup.

Note: you can also just run this interactively in the IPython interpreter.

1. Use IPython as a system shell, and integrate bash code with python code!
Using SList, you can do all sorts of transformations on output from bash commands.

1. A whole new replacement for python (and bash) scripting! Supports pure python + IPython + bash (as it works in IPython)

Use this program to execute scripts

An example script

Execute script

* Note: There is also a method in IPython core that (I believe) attempts to achieve a similar effect:


Unfortunately, it doesn’t work very well

##### For more tips

Checkout the notes for my talk on tmux and ipython:

Or the video of my talk: HERE (python in the second half)