While trying to configure the programmable completion, I came across a behavior I don't understand.
Given those three completion scenarios, this is the way I understand them:
$<TAB><TAB>
Beginning of the line --> use complete -E
--> if it doesn't exist, use complete -D
--> if it doesn't exist, use the default Bash completion --> there are no words on the line --> use command completion.
$com<TAB><TAB>
Trying to complete first word --> use command completion.
$command argu<TAB><TAB>
There is at least one word on the line --> trying to complete an argument --> use complete
for the given command --> if it doesn't exist, use complete -D
--> if it doesn't exist, use the default Bash completion --> there is already at least one word on the line so don't use command completion --> doesn't start with $
, ~
or @
so perform filename completion.
My question is why is the filename completion performed instead of command completion in this scenario even though there are no words on the line yet:
$<SPACE><TAB><TAB>
It's even more confusing since the command completion below is performed as expected:
$<SPACE>com<TAB><TAB>
I most likely misunderstood the manual and I would be most grateful for any explanation.
NOTE:
$
denotes the prompt, not a literal dollar sign.
Using autocomplete is as simple as pressing the [TAB] and the active command line options will fill-in. If more than one option is available, you can hit [TAB] twice to display all possible choices and continue typing until there is only one matching choice left.
Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands.
Bourne shell and csh do not, but ksh, bash, tcsh, and zsh all have tab completion to varying degrees. The basic principle in all of these shells is the same; you type the start of the word, hit the <TAB> key twice, and the list of possible commands or files is displayed.
When a line starts with a blank in a Bash shell, this tells the shell that the command should not go into the command history. This can be configured by setting the HISTCONTROL
env variable in your .bashrc
, .profile
or whatever file you want and should be the default behavior (see also How to prevent commands to show up in bash history?).
So command execution is the same when the line has a leading blank except that this command doesn't go into history. Thus, code completion also behaves the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With