linux环境下tab 自动补全功能

来源:互联网 发布:上海网络教育本科 编辑:程序博客网 时间:2024/05/20 17:24

也许你是老油条,但是用惯了开发工具,在linux下也会有一脸懵b的时候,然后各种dir(),help(),查方法,今天要介绍的就是更快捷的方法。

大家都比较喜欢shell环境下,随便敲下自己想操作命令的前1个或几个字母,就可以使用tab键快速的补全剩余的命令,或查看这些字母开头的所有命令,实际上在python shell中,我们也可以实现这个功能,下面我们来一起看一下:

1:首先我们需要得到python目录(注意红色圈起来的路径)


2:第二步需要到该目录下写一个tab脚本(/usr/local/lib/python2.7/dist-packages)


#!/usr/bin/python  # python tab file  import sysimport readlineimport rlcompleterimport atexitimport 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:    passatexit.register(readline.write_history_file, histfile)del os, histfile, readline, rlcompleter


3: 切换至家目录下,添加环境变量(.bashrc)---> source .bashrc


4: root用户可以直接使用tab,其他用户需要先导入tab模块(import tab)

其他用户:


import 后









1 0