Terminal & the 'tab' key

Apparently when you press the ‘tab’ key with nothing else on the command line, Terminal will display the entire compliment of unix commands piped to ‘more’. If you have some characters on the command line, Terminal will display only the commands that begin with those characters.

Can anyone tell me what command(or is this a shell script?) I can use to get the same data without the initial y/n user query or ‘more’?

TIA
Jeff

Using the TAB key like that invokes bash’s completion system. The completion system uses the text that has already been entered to search for possible completions to commands, filenames, usernames, hostnames, and other, programmable categories. Generally, command completion is used for the first ‘word’ of the command line. Command completion uses the preceding text as a prefix to search through the list of all the shell aliases, all the shell reserved words, all the shell functions, all the shell built-in commands, and all the executable binaries in the directories of the PATH. With no input on the command line, the prefix is empty, and thus all the potential commands match the prefix.

The ‘paging’ that is done is not actually done by more, but by an internal work-alike. You can turn off this completion paging entering bind ‘set page-completions off’. This will only affect the current shell process.

The y/n prompt is based on a configurable limit that defaults to 100. If there are fewer possible completions than the configured limit, bash just shows them, otherwise it gives the y/n prompt to avoid overwhelming the user with a potentially huge amount of data (this is especially nice when operating over a slow connection). While there is no way to completely disable this prompt you can effectively disable it by giving it a tremendously high limit. bind ‘set completion-query-items 4294967296’ sets the limit to 2^32 (again, only for the current shell process).

You could add both commands to your .bash_profile file to have them set for every new login shell (i.e. each new Terminal window).

The above is only applicable for interactive use (e.g. typing a prefix and then TAB or some other completion key sequence). bash also has a command to activate the completion logic outside of interactive use. The command is compgen (as in completion generator). To generate a list of ‘all’ commands like TAB-in-an-empty-command-line does, use compgen -c. To get the commands that start with “foo” use compgen -c foo.

Thanks for the thorough post chrys (I didn’t know about compgen); Now, if I may add one more thing to it.

do shell script "compgen -c | /usr/bin/sort --unique --ignore-case"
set example to paragraphs of result

Thanks chrys! This is a part of a small utility to create PDF files for the compliment of unix commands. The CommandFinder utility came real close, but I wanted to be able to dynamically generate this complete list of commands so it can be browsed without any initial filtering. When I have something sharable I will post another reply.