Image 01

Transneptune

beyond the Kuiper Belt, over the sea

iPython as your default shell

June 16th, 2009 by

At the request of Ultranurd, allow me to explain my new shell set up.

I’m sick of bash.  The syntax is absurd, and absurd syntax makes me sad. So I’ve just recently set up iPython as my shell. What follows are the relevant config files and some explanation.

First, we want to make sure that iPython is installed, and if we’re on OS X, that it’s installed for Python 2.6. The reason for this is that earlier versions of Python don’t handle tab completion and command line history well—by using libedit rather than readline proper, they have some bugs that make things still strictly speaking functional, but hardly visually appealing.  You’ll have to trust me, as I don’t want to find the words to explain the ways it looks bad.

So, for OS X, download Python 2.6, install it, and download the latest stable source for iPython and install it with Python 2.6.  Something like this:

curl http://www.python.org/ftp/python/2.6.2/python-2.6.2-macosx2009-04-16.dmg -o python-2.6.2-macosx2009-04-16.dmg
open python-2.6.2-macosx2009-04-16.dmg
# do the installer dance
curl http://ipython.scipy.org/dist/ipython-0.9.1.tar.gz -o ipython-0.9.1.tar.gz
tar -xzvf ipython-0.9.1.tar.gz
cd ipython-0.9.1.tar.gz
sudo ./setup.py install

Now, to make sure it’s working, run ipython and you should see Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) or something like it as the first line. The key part is the 2.6.2.

Now, to make this your shell. The Proper Right and True way would involve chsh, but because I like to sync my homedir configurations across many systems I operate on, I’ve done it the Immoral Bad and Evil way, by just appending exec /usr/local/bin/ipython -noconfirm_exit -p sh to my .bashrc.

Let me unpack that line. exec is a bash builtin that executes a command, replacing bash with that command. /usr/local/bin/ipython is just a fully qualified path to ipython; ymmv. -noconfirm_exit gets rid of the “are you sure you want to quit?” on ctrl-D, which I find annoying. Again, ymmv. Most importantly, there’s -p sh. Dark secret, I actually have -p kit, which loads a custom profile called kit. But the idea is the same, and that profile is based off of the builtin sh profile. I won’t go in to making a custom profile here; start with sh and play around with it.

Save the relevant files, open a new terminal just to make sure nothing’s borked (leaving your old terminal still open!). You should see something like

Last login: Tue Jun 16 18:01:54 on ttys000
IPython 0.9.1   [on Py 2.6.2]
kit@morgana[~]> 

Now, you can pretty freely mix Python and shell commands. If you need to escape something to be shell-y, and make sure it doesn’t get pythonized, just prepend a !. Enjoy. Comment with questions; I’ll elaborate.

Tags: , ,

  • Geroge

    Can you post some examples that would convince people that are pretty happy with bash that you are basically a million times cooler than they are?

    So, let me be the devil’s advocate and ask why you would want ipython as your default shell? Amaze us!

  • http://transneptune.net kit

    I’m not sure I have much amazing to do; it’s just more fun to do things using python, like, say, simple renaming loops and if you ever have to make a conditional, dealing with bash’s weird behavior (which varies between a condition in [[ ]] and [ ]) is nice to avoid.

  • http://tartley.com Jonathan Hartley

    Hey. I’m on Windows today. When I run an IPython session, I lose the ability to browse through previous commands using the up and down arrow keys. Does anyone know why that happens? Or how else I can trigger the same behaviour?

  • http://tartley.com Jonathan Hartley

    SOLUTION: ‘easy_install pyreadline’ to have up/down arrow keys browse command history on Windows. Plus some other things (like colors!) work now.

  • http://transneptune.net kit

    Just so.

  • Wladimir J. van der Laan

    I so agree on the crappy syntax of bash. I’m so sick of it and as I do a lot of data manipulation I wish I had a better shell based on a real language such as Python.
    I’m trying to switch to ipython (pysh mode) but it is still a big step.
    Especially the things requiring output redirection (piping) and “backticks” I’m not sure how to do conveniently in ipython yet.
    Then again, once I figured out I’ll probably never want to go back to bash.

  • http://transneptune.net kit

    I’ve actually gone back to bash myself; ipython is not yet quite usable as a shell. Close, but not quite.

  • Pingback: Why are scripting languages (e.g. Perl, Python, Ruby) not suitable as shell languages? - Question Lounge

  • Pingback: Why are scripting languages (e.g. Perl, Python, Ruby) not suitable as shell languages?

  • Pingback: Why are scripting languages (e.g. Perl, Python, Ruby) not suitable as shell languages? | BlogoSfera

  • ravin sharma

    I’m having frustration with bash too. Bash is cool and stuff, and its absurd syntax. Just switched to IPython.

  • http://games.transneptune.net/ Kit La Touche

    Crucially, note my comment below: I quickly ended up moving back to bash. The IPython thing was a fun diversion, but it just wasn’t as usable for daily shell-usage.

  • ravin sharma

    I know it been four years since you posted this article, but what do you think makes bash has more advantage than ipython?

  • http://games.transneptune.net/ Kit La Touche

    Basically, process management and pipes. Getting things in and out of processes is something that bash, syntactically, handles very well, and Python, syntactically, not as well.

  • ravin sharma

    Yeah, exactly the things i noticed too.. Maybe there is a pipe function replacement, need to look at it later. Thanks for the time.