Bash Filling a tab with argparse does not display all files in a directory

I noticed that completing the bash tab returns fewer files if I use the argparse option. How can I change / control this?

minimal code example

me@here:~/test$ cat argparsetest.py 
import argparse
parser.add_argument('-i', help='input', required=True)

bash completion examples:

# 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            

There are already two similar questions, but I did not find them useful.

+3
source share
1 answer

argparse Python. , , " bash ", , "python".

- python:

#!/usr/bin/env python

Python script:

me@here:~/test$ chmod u+x argparsetest.py 

, "python":

me@here:~/test$ ./argparsetest.py<TAB>
argparsetest.py  result.png       u1.py  

me@here:~/test$ ./argparsetest.py -i<TAB>
argparsetest.py  result.png       u1.py  

bash

complete -r

, , ~/.bashrc /etc/bashrc, , , :

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi
+4

All Articles