Python 使用argparse完成Bash选项卡不会显示目录中的所有文件
我注意到,如果使用argparse参数,bash tab completion返回的文件会更少。我怎样才能改变/控制它 最小示例代码Python 使用argparse完成Bash选项卡不会显示目录中的所有文件,python,bash,shell,argparse,Python,Bash,Shell,Argparse,我注意到,如果使用argparse参数,bash tab completion返回的文件会更少。我怎样才能改变/控制它 最小示例代码 me@here:~/test$ cat argparsetest.py import argparse parser.add_argument('-i', help='input', required=True) bash完成示例: # shows all the files me@here:~/test$ python argparsetest.py a
me@here:~/test$ cat argparsetest.py
import argparse
parser.add_argument('-i', help='input', required=True)
bash完成示例:
# shows all the files
me@here:~/test$ python argparsetest.py
argparsetest.py result.png u1.py
# does not show the image result.png I am actually interested in
me@here:~/test$ python argparsetest.py -i
argparsetest.py u1.py
已经有两个类似的问题,但我觉得它们没有帮助
#!/usr/bin/env python
,然后使Python脚本可执行:
me@here:~/test$ chmod u+x argparsetest.py
然后直接调用它,而不显式调用“python”:
而且,如果您想在以后的会话中禁用它,请注释掉或删除~/.bashrc或/etc/bashrc上可能如下所示的行:
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
我无法重现这种行为。python 2.7.2,bash完成版本
1:1.3-1ubuntu6
。带和不带-i
的选项卡都包含png文件。此外,在最小代码中缺少一行,如parser=argparse.ArgumentParser(description='do things')
。
complete -r
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi