如何將您的bash別名移植到IPython版本> = 0.11?如何將bash別名移植到ipython> 0.10?
這個問題已經回答了IPython的< 0.11,並鏈接是 這裏:
http://ipython.scipy.org/Wiki/tips
如何將您的bash別名移植到IPython版本> = 0.11?如何將bash別名移植到ipython> 0.10?
這個問題已經回答了IPython的< 0.11,並鏈接是 這裏:
http://ipython.scipy.org/Wiki/tips
這裏是我的解決方案。改進歡迎!
在你的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]
如果你在別的文件中定義了別名你需要做'os.popen(「bash -lc'./the/file/where/you/have/aliases&& alias'」).read()'。這對於zsh也適用。 –
這不起作用在ipython 0.13.2中,函數'get_config()'不存在。 – qed
重要提示:我的〜/ .bashrc被設置爲不在非交互模式下執行,因此''bash -lc 「'沒有任何返回,如果你有同樣的問題,試試'os.popen(」bash -lci alias「)''-i'選項用於交互模式,並且使得bash的事情像往常一樣。 –
這看起來好了,所以...有什麼問題嗎? – wim
亞歷克斯,最好在問題中提問你的問題,然後把答案寫成這個問題的答案 - 如果沒有人提供更好的方法去做,那麼接受你的答案:-) –
你想把它放在IPython維基上? http://wiki.ipython.org/Cookbook/Moving_config_to_IPython_0.11 –