如何将bash别名移植到ipython > 0.10?

3 投票
1 回答
676 浏览
提问于 2025-04-17 03:16

你怎么把你的bash别名移植到IPython 0.11及以上版本呢?

这个问题在IPython 0.11之前已经有人回答过,相关链接在这里:

http://ipython.scipy.org/Wiki/tips

1 个回答

2

这是我的解决方案,欢迎提出改进意见!

在你的ipython配置文件中,添加以下几行代码:(我的配置文件在这里:~/.config/ipython/profile_default/ipython_config.py)

c = get_config()

## Port bash aliases to ipython
import os, string
a = os.popen("bash -l -c 'alias'").read()
a = a.translate(string.maketrans("=", ' '), '\'"').split('alias ')
a = [tuple(x.strip().split(' ', 1)) for x in a]
c.AliasManager.user_aliases = [x for x in a if len(x) == 2]

撰写回答