How to use ~/.bashrc aliases on IPython 3.2.0?

I need to use my aliases from ~/.bashrc on IPython.

First I've tried but it didn't work

source ~/.bashrc

According to this post we should do

. ~/.bashrc
f2py3 -v

It takes 20 sec to run on Jupiter and I get:

bash: line 2: f2py3: command not found

My ~/.bashrc file looks like

alias f2py3='$HOME/python/bin/f2py'

bash: line 2: type: f2py3: not found

Neither alias, source, nor %rehashx% work

alias f2py3='$HOME/python/bin/f2py'

I actually found that the problem is Python, who can't execute alias command neither with sh nor bash.

Can I use alias with IPython magics?


You can parse your bashrc file in the ipython config and add any custom aliases you have defined:

import re
import os.path

c = get_config()

with open(os.path.expanduser('~/.bashrc')) as bashrc:
    aliases = []
    for line in bashrc:
        if line.startswith('alias'):
            parts = re.match(r"""^alias (\w+)=(['"]?)(.+)\2$""", line.strip())
            if parts:
                source, _, target = parts.groups()
                aliases.append((source, target))

    c.AliasManager.user_aliases = aliases

This should be placed in ~/.ipython/profile_default/

%rehashx makes system commands available in the alias table so is also very useful if you want to use ipython as a shell.

Need Your Help

CakePhp 2.0 .htaccess

.htaccess cakephp mod-rewrite cakephp-2.0

Having trouble configuring CakePhp on an Apache server. It worked fine in my dev environment, and now I'm looking to deploy.