2

I have a folder ~/TestFolder. The current working directory is the home directory(~).

I want to enter a partial command, for example cd test, and I want it auto filled to give the command cd TestFolder upon pressing Tab.

How can I achieve this?

6
  • 4
    How about cd Test and then Tab? It may be about case sensitivity. Or do you explicitly want your tab completions to be case-insensitive? What is the shell? Jan 5 at 10:07
  • 1
    Tab completion is a feature of your shell (default is bash on most Linuxes, zsh on up-to-date Macs). But unix-style file and directory names are case sensitive: in a single directory, both test and Test could exist at the same time, and be two different files or directories. Usually, the shell will not change the case of typed characters on tab-completion, but your shell might have an option to enable it.
    – telcoM
    Jan 5 at 10:08
  • Hi! And welcome here, Dugu02! As the others have pointed out, this is a functionality of the shell. We don't know which shell you are using! could you tell us what echo $SHELL says? Jan 5 at 10:37
  • I use /bin/bash on Ubuntu 20.04
    – Duc Dat
    Jan 5 at 10:45
  • 1
    @gidds Zsh can be configured to do case-insensitive completion. Jan 5 at 12:48

1 Answer 1

2

Bash

Add the following to your ~/.bashrc-file:

bind -s 'set completion-ignore-case on'

This enables case-insensitive completion in bash, as explained by Gilles' answer in How to make cd arguments case INsensitive?.

Tested with bash 5.0.17 on Ubuntu 20.04.

Other options

I have only tested bash and zsh. This is what I found out for other shells:

The other option in the linked answer adds set completion-ignore-case on to inputrc. That could be used by other shells, too. According to this answer, which also talks about whether to use this option with bash.

Therefore, if not using bash, researching your specific shell first is a good idea (unless others will add tested answers for other shells).

Zsh

zsh uses a different line editor and not readline/inputrc. On install it gives the option to press 2 to add a recommended ~/.zshrc, which already includes the following line. It makes the the desired behaviour work out of the box:

zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za- z}' 'r:|[._-]=* r:|=* l:|=*'

Tested with zsh 5.8 on Ubuntu 20.04.

This also might be helpful: Combining zsh’s tab completion with case insensitivity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.