afurlan's blog

/^random (nerd|geek)? posts$/

Using IPython as your default shell

Thursday, October 29, 2009 - 46 comments

If you are a shell addicted person and like Python, then the IPython was made just for you! The IPython provides a very usefull feature (that may looks a bit strange at first) of mixing Python and Shell commands in a easy and intuitive way. I don't pretend to say why you should use IPython instead of your current shell but I think that, if you know Python, you should prefer to write Python code instead of Bash code.

I'll assume that you already have the IPython installed but if you don't, take a look at IPython's documentation to see how to install it. I'm running Debian and my setup is focused in my machine, so it should work for the most of the others linux distros but if you are running a different system, I'm sorry for you you may have to adapt some commands and/or paths. :)

Configuring the IPython's prompt

The first time you run IPython, it displays a warning about the creation of your personal configuration directory. One of the most important parts of this warning is about the new configuration file: ~/.ipython/ipy_user_conf.py. So let's configure this file and the IPython's prompt to make it looks exactly like the Debian's prompt. Edit your configuration file and change the following settings as below:

...
import ipy_profile_sh
...
o.prompt_in1 = r'\C_Normal\u@\H:\Y2$ '
o.prompt_in2 = r'\C_Normal... '
...

The first option, import ipy_profile_sh, avoid you to have to escape all the Bash commands. The second and third options, o.prompt_in1 and o.prompt_in2, change the IPython's prompt. And now start the IPython as follow:

afurlan@merlin:~$ ipython -nosep -nobanner -noconfirm_exit
afurlan@merlin:~$
afurlan@merlin:~$ 
afurlan@merlin:~$ print 'hello python!'
hello python!
afurlan@merlin:~$ echo 'hello bash!'
hello bash!

Now you're able to run Python commands:

afurlan@merlin:~$ for line in open('domains.txt'):
              ...     print line
              ...    
              ...    
afurlan.org

blog.afurlan.org

And a mixed of Python and Bash commands:

afurlan@merlin:~$ for line in open('domains.txt'):
              ...     echo "$line"
              ...    
              ...    
afurlan.org

blog.afurlan.org

afurlan@merlin:~$ for line in open('domains.txt'):
              ...     echo "$line.strip()"
              ...    
              ...    
afurlan.org
blog.afurlan.org

Setting the IPython as your default shell

Actually I don't like to set the IPython as my default shell... I use to run screen so I configure it to open five IPython sessions by default but if you really like to set it as your default shell, you can add the following line at the end of your ~/.bashrc file:

...
exec ipython -nosep -nobanner -noconfirm_exit

If you're a screen user too, you can add the following lines at your ~/.screenrc:

...
# open 5 ipython sessions by default
screen -t p 1 ipython -nosep -nobanner -noconfirm_exit
screen -t p 2 ipython -nosep -nobanner -noconfirm_exit
screen -t p 3 ipython -nosep -nobanner -noconfirm_exit
screen -t p 4 ipython -nosep -nobanner -noconfirm_exit
screen -t p 5 ipython -nosep -nobanner -noconfirm_exit
...

Or, if you like, you can also get my current .screenrc file.

And, as always: if you found some english bug, warn me and I'll be glad to fix it. :)

Comments

  • gravatar-enrico Hi arthur!
    Very nice tips.
    There's a mistake on the second paragraph, it would be better to use: "... so it should WORK for most of THE others linux distros ...".
    Take care!
  • gravatar-arthur-furlan Fixed, thanks Enrico. :)
  • gravatar-jorge-vargas Awesome, I'm totally trying this out for a week. That tip about mixing bash and python is epic.
  • gravatar-watch-eclipse-online wpcsvszzaaydizqhggql, <a href="http://www.thisis50.com/forum/topics/watch-twilight-eclipse-online">watch eclipse online</a>, qbwwkpq.
  • gravatar-baby-grindin-f nuyglsdbalef, <a href="http://blogesaurus.com/baby-grinding-teeth/">baby grinding teeth</a>, njdsbfkh.
  • gravatar-watch-twilight-eclipse-online-free ssepuuoiasaiikmfflba, <a href="http://pioneer411.com/2010/06/watch-twilight-eclipse-online-free-mckjgeiopa8">twilight eclipse online free</a>, nyuetxk.
  • gravatar-mbt mbt <a href="http://www.mbtfan.com/">mbt</a>
    mbt 靴 <a href="http://www.mbtfan.com/">mbt 靴</a>
    mbt シューズ <a href="http://www.mbtfan.com/">mbtシューズ</a>
  • gravatar-watch-twilight-eclipse-online-free zbthezikdbhpkmkvadmp, <a href="http://freeringtonesfor.org/2010/06/watch-twilight-eclipse-online-bukeodshspyi34">twilight eclipse online</a>, crznnjk.
  • gravatar-catherinelindsay27 It is understandable that cash can make people independent. But how to act when someone does not have cash? The one way only is to get the <a href="http://lowest-rate-loans.com">loans</a> or just bank loan.
  • gravatar-otidgtanog <a href=http://xboxfriends.com/forums/t/263.aspx > tramadol prescription drug jadual </a>
    <a href=http://trailfire.com/Buy_Ativan_No_RX > buy cheap ativan migrated </a>
    <a href=http://www.worldkidneyday.org/forum/topics/buy-ultram-no-prescription-3 > buy ultram no prescription </a>
    <a href=http://www.day26online.com/profiles/blogs/soma-by-money-order-soma-ups > soma by money order </a>
    <a href=http://www.day26online.com/profiles/blogs/buy-acomplia-no-prescription-1 > buy acomplia no prescription </a>
    <a href=http://trailfire.com/Buy_Klonopin_No_RX > Klonopin cod overnight delivery outlet </a>
    <a href=http://www.wfmtintroductions.com/profiles/blogs/cash-on-delivery-online-no > cash on delivery online soma </a>
    <a href=http://wfnx.com/members/Buy-soma-cod.aspx > Buy soma cod </a>
    <a href=http://www.filmsbyus.com/profiles/blogs/buy-tramadol-with-no > buy tramadol with no prescription </a>
    <a href=http://wfnx.com/members/Xanax-no-prescription-US.aspx > Xanax no prescription US </a>
    <a href=http://www.filmsbyus.com/profiles/blogs/buy-lexapro-no-prescription > buy lexapro no prescription </a>
    <a href=http://www.worldkidneyday.org/forum/topics/buy-prednisone-no-prescription-7 > buy prednisone no prescription </a>
    <a href=http://xboxfriends.com/forums/t/313.aspx > cialis sales uk faked </a>
    <a href=http://wfnx.com/members/soma-cash-on-delivery.aspx > soma cash on delivery </a>
    <a href=http://xboxfriends.com/forums/t/264.aspx > valium money orders yourdomainowsadm </a>
    <a href=http://www.wfmtintroductions.com/profiles/blogs/buy-meridia-no-prescription > buy meridia no prescription </a>
    <a href=http://wfnx.com/members/Soma-without-prescription.aspx > Soma without prescription </a>
    <a href=http://wfnx.com/members/Soma-no-prescription.aspx > Soma no prescription </a>
    <a href=http://www.inkedinc.net/profiles/blogs/buy-strattera-no-prescription > buy strattera no prescription </a>
    <a href=http://xboxfriends.com/forums/t/265.aspx > ultram online medication Elisa </a>
    <a href=http://xboxfriends.com/forums/t/318.aspx > ambien no script could </a>
    <a href=http://www.imiaweb2taskforce.org/node/847 > online pharmaceutical Accutane organisations </a>
  • gravatar-facebooklayo Create a custom Facebook profile page for free. Chec out the themes here http://5b56bee0.zxxo.net
  • gravatar-acheter-kamagra Pharmacie en lighe francaise - medicaments generiques de qualite: <a href=http://www.forumfr.com/membre127287-100acheterkamagra.html>acheter kamagra</a> sans ordonnance.
    <a href=http://www.forumfr.com/membre127275-acheter0viagra0generique.html>acheter viagra generique</a> Livraison rapide en Europe.
  • gravatar-benetimigo <a href=http://russian-brides-best.com/>dating website</a>
    http://russian-brides-best.com
  • gravatar-senetimigo <a href=http://zajnabelench.tripod.com/cat1/qvc-layoffs-1.html>qvc layoffs</a>
    <a href=http://zajnabelench.tripod.com/cat7/vanishing-twin-gestation-129.html>vanishing twin gestation</a>
    <a href=http://zajnabelench.tripod.com/cat7/garden-city-shopping-centre-perth-layout-374.html>garden city shopping centre perth layout</a>
    <a href=http://zajnabelench.tripod.com/cat1/aone-ultra-wmv-converter-170-165.html>aone ultra wmv converter 1.7.0</a>
    <a href=http://zajnabelench.tripod.com/cat7/nabgroup-jpg-371.html>nabgroup jpg</a>
    <a href=http://zajnabelench.tripod.com/cat8/stream-robotrix-370.html>stream robotrix</a>
    <a href=http://zajnabelench.tripod.com/cat6/humble-bankruptcy-lawyer-438.html>humble bankruptcy lawyer</a>

  • gravatar-cndeueujs Watch Twilight Eclipse Online Free fgxcdvg5bh6 http://identi.ca/watchtwilighteclipseonlinefree86 bhja3us
  • gravatar-denskirlenelp denSkirlenelp
    <a href=http://needman.ru>знакомства с иностранцами</a>
    знакомства с иностранцами
    http://needman.ru
    DowPhevevom
  • gravatar-cialis-generique <a href=http://forum.todae.fr/index.php?showuser=13267>Cialis generique</a> en ligne sans ordonnance. Pharmacie en ligne - prix bas, livraison en Europe rapide, medicamentss generiques de qualite.
  • gravatar-snubcuhdync Rummalkmeance
    <a href=http://www.ekccc.org>adipex pills</a>
    Snubcuhdync
    <a href=http://noweatthis.net>buy ambien overnight</a>
    inobreboovits
    <a href=http://www.thegibsoncompany.com>lorazepam vs xanax</a>
    LoldElulley
  • gravatar-snubcuhdync Rummalkmeance
    <a href=http://www.ekccc.org>canada online prescriptions adipex</a>
    Snubcuhdync
    <a href=http://noweatthis.net>buy ambien</a>
    inobreboovits
    <a href=http://www.thegibsoncompany.com>mixing diazepam and lorazepam</a>
    LoldElulley
  • gravatar-snubcuhdync Rummalkmeance
    <a href=http://www.ekccc.org>adipex versus phentermine</a>
    Snubcuhdync
    <a href=http://noweatthis.net>side effects of ambien</a>
    inobreboovits
    <a href=http://www.thegibsoncompany.com>lorazepam side effect</a>
    LoldElulley
  • gravatar-ford-keyless-entry-code mqohqmivdadozzvjnfdk, <a href="http://www.underground-secret.com/ford_keyless_entry_code.html">ford keyless entry code</a>, nzsxqlt.
  • gravatar-lose-chest-fat zbpdvnyerrktrpxrecov, <a href="http://blogesaurus.com/how-to-lose-chest-fat-for-men/">How to Lose Chest Fat for Men</a>, kpzhvhc.
  • gravatar-increase-free-testosterone smvxmhuotxlpyyrdoxhc, <a href="http://increasefreetestosterone.com/">increase free testosterone</a>, cwcnudf.
  • gravatar-watch-true-blood-online ygipolrbblfqciazybbx, <a href="http://www.thisis50.com/forum/topics/watch-true-blood-online-free">watch true blood online </a>, sffagdz.
  • gravatar-snubcuhdync Rummalkmeance
    <a href=http://www.ekccc.org>how does adipex work</a>
    Snubcuhdync
    <a href=http://noweatthis.net>ambien addiction</a>
    inobreboovits
    <a href=http://www.thegibsoncompany.com>lorazepam vs xanax</a>
    LoldElulley
  • gravatar-ford-keypad-code hfkqrwcaomogpgrwjypl, <a href="http://pioneer411.com/2010/07/ford-keypad-door-code-guide/">ford keypad code</a>, ydeqvtq.
  • gravatar-uninnireple how to get free health insurance

    <a href="http://amdzhadleono.tripod.com/cat5/mortgage-interest-payment-insurance-128.html">mortgage interest payment insurance</a>

    what is comprehensive insurance

    <a href="http://anisrimar14.tripod.com/map.html">local 385 firefighters negotiated insurance benefits</a>

    budget insurance services

    <a href="http://evgenijalozi.tripod.com/cat6/taylor-insurance-sandpoint-id-457.html">taylor insurance sandpoint id</a>

    florida insurance commission

    <a href="http://ierofejsopin.tripod.com/cat8/thomas-holloway-insurance-brokers-brisbane-490.html">thomas holloway insurance brokers brisbane</a>

    auto insurance companies ratings

    <a href="http://manalfavstov.tripod.com/cat3/dental-insurance-wilmette-il-521.html">dental insurance wilmette il</a>

    fema national flood insurance

    <a href="http://nadzhibfranc.tripod.com/cat4/bantleman-insurance-olean-185.html">bantleman insurance olean</a>

    churchill insurance for home uk

    <a href="http://saidsartov47.tripod.com/cat6/ibex-car-insurance-609.html">ibex car insurance</a>

    progressive insurance locations

    <a href="http://stefantjurin.tripod.com/cat4/questions-alabama-auto-insurance-432.html">questions alabama auto insurance</a>

    semi truck insurance companies

  • gravatar-ford-keypad-code-location eyvjkozbevvjrhqmfhpi, <a href="http://freeringtonesfor.org/2010/07/ford-keypad-code-location-guide/">ford keypad code location</a>, mafxzto.
  • gravatar-lg-lotus-turns-off qauzlvsilromzgdxriza, <a href="http://lglotusturningshuttingoffguide.blogspot.com/">lg lotus turns off</a>, fdluaqz.
  • gravatar-acer-aspire owtglpgadkbtmxywjyyz, <a href="http://blogesaurus.com/acer-aspire-as5740-5255-reviews/">Acer Aspire AS5740-5255 Reviews</a>, tsplhqh.
  • gravatar-nokia-review pnisagvjeyxuhkkmdrtv, <a href="http://hubpages.com/hub/NokiaN900Review">nokia n900 review</a>, ypsofff.
  • gravatar-wife-caught-cheating ikphbrqkxelakivfufoc, <a href="http://wifecaughtcheating.net/">wife caught cheating</a>, zhzjykt.
  • gravatar-reciprocal-link-checker fvbwlbbctmbdiyxfkglz, <a href="http://reciprocallinkchecker.org/">reciprocal link checker</a>, jfhdvnt.
  • gravatar-satelliteolliut <b><a href=http://075fcltjbhxbb0a3vsre59azdh.hop.clickbank.net/>Get It Here</a></b>

    SatelliteDirect Tv Website. Get Up To 3,500+ HD Channels On Your Computer For A Small One-Time Fee Unlimited Usage.

    <b><a href=http://075fcltjbhxbb0a3vsre59azdh.hop.clickbank.net/>Get It Here</a></b>

    About few years you become reaching the 3.500 tv channels on the internet so; show that Satellite Direct software technology develop quickly day to day. How do you use that technology? You can use your cable with your satellite Tv then you can enjoy this. High point is about this service that you'll pay one-time fee less than one month of your monthly cable bill.

    If you don't want to any complication you can reach with a computer and an internet connection. First you must download our software and enjoy over 3.500 channels worldwide.

    Everything about that, it is so simple. Now you can watch 3.500 TV channels worldwide in anywhere and when you want to do. If that is fascinate you can only be a member and enjoy all tv channels

    <b><a href=http://075fcltjbhxbb0a3vsre59azdh.hop.clickbank.net/>Get It Here</a></b>

    Enjoy It! Thank you reading
  • gravatar-watch-avatar-online-free gvlsrolkpjldzrjkirtu, <a href="http://watchavataronlinefree.wetpaint.com/">watch avatar online free</a>, avogepm.
  • gravatar-swiss-replica great blog! very interesting read
  • gravatar-lose-arm-fat tajnegxhwevfgfxrublz, <a href="http://blogesaurus.com/how-to-lose-arm-fat-for-men-and-women/">how to lose arm fat</a>, crdujew.
  • gravatar-twilight-new-moon wydydgvyyxuyfryxfpyh, <a href="http://watchtwilightnewmoononlinefree.wetpaint.com">watch twilight new moon online free</a>, iwhxpew.
  • gravatar-incibebeerymn Без салонов красоты и студий загара сложно представить нашу жизнь. Мы уже сами, не осознавая происходящего, регулярно посещаем студии загара, пользуемся услугами салонов красоты. Если нам предложить отказаться от данных услуг, мы испытаем как минимум шок...
    А что бы его не испытывать есть<a href=http://baseall.ru>Рейтинг салонов красоты </a>
  • gravatar-true-blood jhsdgwkabzjioaiiabos, <a href="http://www.thisis50.com/forum/topics/watch-true-blood-online-free">watch true blood online</a>, bbcusxw.
  • gravatar-the-hurt-locker erucfbmqrrqspnlaztlx, <a href="http://www.dailymotion.com/video/xe6cne_watch-the-hurt-locker-online-free-f_shortfilms">watch the hurt locker online</a>, gtpozns.
  • gravatar-tureduero Проект <a href="http://moskow-sun.ru">Топ соляриев </a> является эксклюзивным порталом в отрасли загара. Портал является структурированной системой объединяющей студии загара, и предоставляющей объективную оценку работы салонов. Объективность оценок в первую очередь достигается с помощью ваших отзывов и оценок студий загара.
  • gravatar-lose-butt-fat ralwknmksszuintnqzby, <a href="http://blogesaurus.com/how-to-lose-butt-fat-for-men-and-women/">how to lose butt fat</a>, odocquu.
  • gravatar-biotivia-bioforge-review iyqhodvlmczzqcdwoqii, <a href="http://hubpages.com/hub/Biotivia-Bioforge-Review">biotivia bioforge review</a>, bqhbkbq.
  • gravatar-what-is-testosterone swabvmvmheszaykwinbt, <a href="http://hubpages.com/hub/What-is-Testosterone">What is Testosterone</a>, qmruozr.
  • gravatar-unfisifubre TabingefeHing
    Интересные новости и не только в <a href=http://livjurnal.ru>живой</a>
    ReotmelfRom

Trackbacks