Bash autocomplete

Bash autocomplete

Bash autocompletion saves time and reduces errors by completing commands, filenames, and more with the Tab key.

  1. Edit ~/.bashrc and add:
bind '"\t":menu-complete'
bind "set show-all-if-ambiguous on"
bind "set completion-ignore-case on"
bind "set menu-complete-display-prefix on"
  1. Apply changes: source ~/.bashrc

Now, Tab cycles completions, shows all options, ignores case, and displays common prefixes. Faster, easier command-line!

Examples:

  • Command Completion: Type git com and press Tab. It will likely complete to git commit. If multiple options exist (like git compare), pressing Tab twice shows a list.
  • Filename Completion: Type cd Doc and press Tab. If a "Documents" directory exists, it completes to cd Documents/.
  • Option Completion: Type ls --l and press Tab. It can complete to ls --list or other available options.
  • Variable Completion: Type echo $HOME/D and press tab. It will complete the directories in your home directory that start with D.
  • User Completion: Type ssh us and press tab. It will complete to the users on the system that start with us.

Sources:
https://askubuntu.com/questions/280327/how-to-make-terminal-autocomplete-when-there-are-several-files-directory

Bash autocomplete: first list files then cycle through them
Is it possible to configure bash in such a way that on the first tab autocomplete it lists all possible files and on subsequent ones cycles through the choices? Both options are easy to do separa…