tab completion for service command on debian

11,335

First of all check if bash-completion is installed run:

 $ dpkg -l bash-completion | tail -1

it should output something like:

ii  bash-completion  1:1.3-1  programmable completion for the bash shell

If output is empty thus install it with:

aptitude install bash-completion

Then check if it is enabled:

 $ grep -A 2 bash_completion ~/.bashrc /etc/bash.bashrc

Should output something like

~/.bashrc:if [ -f /etc/bash_completion ]; then
~/.bashrc:    . /etc/bash_completion
~/.bashrc:fi

If nothing like this or it is commented (has # after ~/.bashrc:) then add/uncomment

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

to ~/.bashrc and reread it with

. ~/.bashrc

After that it should work fine.

Share:
11,335

Related videos on Youtube

markus
Author by

markus

Updated on September 18, 2022

Comments

  • markus
    markus about 1 month

    I have two systems with debian squeeze installed. On one system when I type:

    service <TAB> 
    

    it shows me all available service (from /etc/init.d)

    on the other system it shows me all files from the current directory. Does anyone know which setting changes that behaviour ?

    UPDATE:

    The file /etc/bash_completion.d/service was missing. I copied it from the machine where it is working. If I type complete -p | grep service it shows me:

    complete -F _service service
    

    On the machine where it is not working that command shows me nothing. I executed complete -F _service service in the command line, after that, the command service <TAB> shows me:

    service -su: completion: function `_service' not found
    

    this function is defined in the service file I recently copied, for some reasons it can't be found ...

    • Janne Pikkarainen
      Janne Pikkarainen over 10 years
      Do you have /etc/bash_completion.d/service file present?
    • markus
      markus about 10 years
      The file wasn't there, I've added it, but it's still not working. I've seen with complete -p I can display all bindings, on the machine where it is working it shows me a lot of binding, where it's not working it displays nothing. I think it doesn't bind for some reason the files in /etc/bash_completion.d ...
  • markus
    markus over 10 years
    bash completion works on both machines, but different. if I type service <TAB> it shows me all services on one machine, on the other one the files of the current directory.
  • rush
    rush over 10 years
    Are versions of bash-completion the same?
  • markus
    markus over 10 years
    same debian versions, some bash-completion
  • markus
    markus over 10 years
    one difference is on server 1 I'm directly on the console, an server 2 I'm connected via ssh.
  • adaptr
    adaptr over 10 years
    Directory completion is NOT bash_completion, which is an ugly hack perpetrated by Debuntu on the readline library (which is what shells use to ...read...lines). bash_completion is NOT enabled on the second box.