So I have a python program that reads a config file like this:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', type=str, help='config file', required=True)
args = parser.parse_args()
cfg_filename = args.config
I want to be able to autocomplete paths in bash. For example, suppose the above program is called main.py and there is a config file called config_1.txt, structured as follows:
folder/
main.py
configs/
config_1.txt
And suppose in my terminal it looks like
user@host:~/folder$ python main.py -c con
I hope pressing one tab gives:
user@host:~/folder$ python main.py -c config/
and then another tab gives
user@host:~/folder$ python main.py -c config/config_1.txt
I've tried adding
import argcomplete
argcomplete.autocomplete(parser)
but didn't work.