I recently wrote a program that can instantly switch to a directory if it has a unique name with respect to some given baseline. For example, if I have a directory:
and foo is a unique end name in all directories under
~/Documents/, then running the program with the command 'foo' will instantly change my current working directory to
~/Documents/foo regardless of where I am currently in the directory tree.
Since these directories, like 'foo' in the example above, have a unique name, I want it to recognize it as a unique name and autocomplete it. For example, if foo is the only directory under
~/Documents that starts with an 'f', I want:
program_name f [TAB]
to autocomplete to:
The problem is that, given the entire purpose of the program, foo is generally not a neighboring directory of my current working directory. Generally, when using the regular
cd function, the terminal autocompletes directories because you're typing each in sequentially along the tree.
Is it possible somehow to add these unique directory names to the autocompletion feature? If possible, I would like it to recognize unique folder names without my having to manually add each one to some file. My program also has different levels to it (e.g. it can actually take up to three arguments, and so long as the third folder name is unique with respect to the tree starting at the second, the second with respect to the first, and the first with respect to some constant baseline like
~/Documents, then it will change my current working directory to the last argument given), so a robust answer would be greatly appreciated to see how I can squeeze the most autocompletion out of the terminal as possible.
Also, I am somewhat of a beginner, so try to say it like I am five :)
Thank you in advance