step 1: 用戶主目錄下創建並編輯文件.pythonstartup,文件內容如下:
#python startup file
import readline
import rlcompleter
import atexit
import os
# tab completion
readline.parse_and_bind('tab: complete')
# history file
histfile = os.path.join(os.environ['HOME'], '.pythonhistory')
try:
readline.read_history_file(histfile)
except IOError:
pass
atexit.register(readline.write_history_file, histfile)
del os, histfile, readline, rlcompleter
step 2: 鏈接至環境變量,在用戶主目錄下的.bashrc文件中增加:
export PYTHONSTARTUP=".pythonstartup"
完成上述配置,即可實現python命令行tab鍵自動補全功能。