How can I make IPython import the aliases defined in my bash profile upon startup?
-
So far I've managed to place python files in ~/.ipython/profile_default/startup, and I have a clean list of aliases to define. Is there a way I can elegantly include my bash aliases as IPython aliases without copying and pasting?
-
Answer:
Here is what I was able to do: # Configuration file for ipython. import re import os.path c = get_config() with open(os.path.expanduser('~/.bashrc')) as bashrc: for line in bashrc: if not line.startswith('alias'): continue parts = re.match(r'^alias (\w+)=([\'"]?)(.+)\2$', line.strip()) if not parts: continue source, _, target = parts.groups() c.AliasManager.user_aliases.append((source, target)) Drop https://gist.github.com/bfontaine/11352254 in ~/.ipython/profile_default/ipython_config.py. It parses your ~/.bashrc, extract aliases and import them for use in IPython. It handles both simple aliases (e.g. alias l=ls) and quoted ones (e.g. alias l="ls -lh"). You might get some warnings if some of your aliases override existing magic commands.
Baptiste Fontaine at Quora Visit the source
Related Q & A:
- How can I make my 360 profile public?Best solution by Yahoo! Answers
- How can I put a picture of myself on my avatar or profile?Best solution by Yahoo! Answers
- How can I make my YouTube Profile better?Best solution by Yahoo! Answers
- How can I make my profile look cooler?Best solution by Yahoo! Answers
- How can I change the name that shows up on my Yahoo Profile?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.