Terminal autocomplete doesn't work properly

229,893

Solution 1

bash-completion is a set of bash scripts which enables customized completion for specific commands.

This is not just for files and directories, but also e.g. for the commands. So you type partial of commands and by hitting Tab we get a auto completion of commands.

Installation

Step 1: Install bash-completion

$ sudo apt-get install bash-completion

And some times it works if we re-installed it by the follwing command:

$ sudo apt-get install --reinstall bash-completion

Step 2: Enable bash-completion in your .bashrc file

Open your gedit ~/.bashrc and if these content doesn't exist there, add them at the end of it and save it.

# enable bash completion in interactive shells
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

Important: After changing the file you need to source your ~/.bashrc with source ~/.bashrc or reopen your Terminal. It should be fixed now.

Solution 2

If your case is terminal tab not working under Xfce, the solution is as follows:

  1. Open Application Menu > Settings > Window Manager.
  2. Click on 'Keyboard' tab.
  3. Clear the 'Switch window for same application' setting.

Window Manager screenshot how to clear switch window for same application

I've found the solution here.

Solution 3

You may also be in a shell that doesn't support auto complete (ex: Bourne Shell | SH). If you want BASH auto complete you need to switch shells, say to BASH (Bourne Again SHell) instead with the command

chsh -s /bin/bash

Source: Ubuntu Wiki - Changing Shells

Solution 4

In my case, I was trying to execute a script ./myScript.sh, and typing ./my[tab] would not auto-complete.

I had to add execute permissions to the file and auto-completion worked.

Share:
229,893

Related videos on Youtube

Ravexina
Author by

Ravexina

I have studied software engineering and artificial intelligence. I Love *nix operating systems, programming, learning and of course... Music :) I'm a MOD at AU, and if you have any question or concern about my decisions/actions, please post them at: https://meta.askubuntu.com and not to my emāil. If you like to contact me, my Ǧmāil is same as my Ūsĕrņame ;) Please don't Ask your questions using ĕmāil... thanks :-)

Updated on September 18, 2022

Comments

  • Ravexina
    Ravexina almost 2 years

    If I start typing a command like apt-g after hitting tab, the shell completes the command to apt-get, but for the second part of the command like install, if I enter some characters like insta, hitting tab, doesn't complete it to install.

    Another example: after I enter sudo hitting tab doesn't complete anything. for example: sudo apt-ge [tab] and nothing.

    I installed Ubuntu using mini iso (40MB network installer), so maybe there is a config that I missed!

    I've added this code to my .bashrc but still it does not works:

    if ! shopt -oq posix; then
      if [ -f /usr/share/bash-completion/bash_completion ]; then
        . /usr/share/bash-completion/bash_completion
      elif [ -f /etc/bash_completion ]; then
        . /etc/bash_completion
      fi
    fi
    

    I have also checked the permission of .bashrc and it's -rw-r--r--.

    I also source the .bashrc after changes using source .bashrc to apply the changes to the new environment but still no effects.

    I use xfce4-terminal so I thought it might be the terminal and not the bash.

    But editing:

    ~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml
    

    And changing:

    <property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>
    

    to:

    <property name="&lt;Super&gt;Tab" type="string" value="empty"/>
    

    Doesn't makes any difference too.

  • user1226868
    user1226868 over 7 years
    Tried accepted awnser, but everything was already in place. This was indeed the solution for me.
  • nullgeppetto
    nullgeppetto over 7 years
    I would like to confirm that adding the above block of code to the ~/.bashrc file did work for me. Just one comment; you don't really need to log out and log in again to make it work (you may not want to terminate what you work in), you could just run source ~/.bashrc.
  • Gilberto Albino
    Gilberto Albino over 7 years
    I had to reopen the Terminal in order for it to work!
  • Gudlaugur Egilsson
    Gudlaugur Egilsson over 6 years
    Completion suddenly stopped working for me, the above steps do not fix the issue. Any ideas on how to troubleshoot the issue? On ubuntu 16.04
  • Hendy Irawan
    Hendy Irawan about 6 years
    Step 2 does it for me. Or get the template from /etc/skel/.bashrc
  • clifgray
    clifgray about 6 years
    Still the solution I needed as of May 2018.
  • Sergio Ivanuzzo
    Sergio Ivanuzzo almost 5 years
    not works with su hyphen (at least for Arch linux) (for example su - username)
  • αғsнιη
    αғsнιη almost 5 years
    @SergioIvanuzzo not sure what issue you are facing you may look at this unix.stackexchange.com/q/219342/72456 it helps, else open your own question for the problem you have.
  • bitsoflogic
    bitsoflogic over 4 years
    Needed this once I connected through xrdp
  • Daniel
    Daniel about 4 years
    for me, only chmod can't autocomplete, any ideas why?
  • CodeMonkey
    CodeMonkey over 3 years
    Not sure which part did it, since I tried all three, but this worked. I had the issue that bash only autocompleted the second parameter, not the first, e.g. cd install/<TAB> would not show the folders inside install, but time cd install/<TAB> would work.
  • JVE999
    JVE999 almost 3 years
    What eventually solved this issue for me was changing the user's shell, via this answer serverfault.com/a/99791/185200