I would like to get the same possible autocomplete list as hitting [Tab][Tab] in bash but with a command. Is there anyway to do that?
Asked
Active
Viewed 2,757 times
1
-
In theory you could `echo -e "\011\011" | bash` (`011` is tab char), but in practice I don't think that will work, ever. – cat Jan 29 '16 at 00:15
2 Answers
4
You can use compgen, which is typically the program that's invoked when you hit tab twice.
$ compgen -c c
cls
case
coproc
command_not_found_handle
caller
cd
command
compgen
complete
compopt
continue
clamd
cracklib-check
cpgr
cupsreject
cupsdisable
cupsaccept
cron
cppw
<100's more lines...>
It includes shell builtins, too! See this question and man compgen.
Note the output is sorted for columnisation (what bash will do), not a single line. You can quite easily sort the output alphabetically, though.
1
If you mean matching files, you may mean:
foo<TAB><TAB>
This should be an alternative:
ls | grep -E '^foo'
If you mean matching programs, you may do so for all directories in $PATH.
Top Sekret
- 135
- 7
-
`ls` for every possible executable in `$PATH`, and then `grep`ing seems like a bad idea to me, YMMV – cat Jan 29 '16 at 00:32
-
When I hit `TAB` twice, I get `Display all 6677 possibilities? (y or n)`, and my `$PATH` isn't even that cluttered. Seems slow to me, anyways. – cat Jan 29 '16 at 00:36