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:
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.
Define an IPython alias within the IPython Interpreter.
Profile Customization: Automatically port bash aliases and run the magic, %rehashx, on startup.
Add the following code to your config file
Note: you can also just run this interactively in the IPython interpreter.
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.
A whole new replacement for python (and bash) scripting! Supports pure python + IPython + bash (as it works in IPython)