Reputation: 562
In unix bash shell, when I type in cd
and then press tab, it lists both directories and files as the available options to choose. Displaying directories and probably links to the directories must be intuitive. Wouldn't listing the files counter intuitive?
For example, ./ and then tab lists only the items that have execute permissions, which is smart.
Why doesn't bash have the same smarts with cd command? Is it a bug?
Upvotes: 1
Views: 2260
Reputation: 20688
Add the following command to your bashrc
:
complete -d cd # or ``complete -A directory cd''
then it'll only auto-complete dirs (including symlinks to dirs) for the cd
command.
See Programmable Completion Builtins in bash's manual for more details.
Upvotes: 2
Reputation: 530920
In both cases, you are getting filename completion. bash
has just enough built-in smarts to recognize that a command name must have executable permission, so it limits ./
+ Tab to executable files. Completing arguments to cd
falls under the domain of programmable completion (because it is possible, though ill-advised, to shadow a built-in command with a completely different command that doesn't necessarily take directories as arguments).
bash
's programmable completion facilities are pretty good, but for whatever reason, it does not actually include any such completions in the base installation. There is a large set of completions available, though, including one for cd
.
Upvotes: 1