Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash programmable completion when typing "first command"

Is there a way how to control completion for first command being typed on bash4 command prompt?

I can control completions for "empty line" with complete -E, but as soon as some characters are typed, bash (or possibly readline) gives me all filenames from PATH, builtin commands (if, then, else...) and functions on completion attempt (TAB).

I was able to avoid PATH entries by unsetting PATH in PROMPT_COMMAND and restoring it by binding function to trap DEBUG, but no luck with getting rid of bash bultin commands completions.

Any ideas?

like image 671
Stanislav Pavlíček Avatar asked May 04 '12 13:05

Stanislav Pavlíček


People also ask

How do you autocomplete a command in Linux terminal?

When at the MS-DOS, Windows command line or a Linux or Unix shell, typing in long file names or directories can become a burden. Use the Tab to autocomplete the names of directories and files while in the command line.

Where do I put bash completion scripts?

Put them in the completions subdir of $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion or ~/. local/share/bash-completion if $XDG_DATA_HOME is not set) to have them loaded on demand.

How can I tell if I have bash completion?

If the autocomplete results contain directories only (no files), then Bash Completion is installed. If the autocomplete results include files, then Bash Completion is not installed. (An example is if you try this in a Docker Ubuntu container).


1 Answers

This is a veritable weak point in the design of bash's programmable completion facilities. Even the “default” command completion -D takes effect for commands on a blank line only (provided that no complete -E is specified). Something like complete -I (for incompletely typed-in commands) is missing.

like image 67
Armali Avatar answered Nov 13 '22 18:11

Armali