1

My terminal autocompletion does not work properly when I use root.

source /etc/bash_completion works if I invoke that manually.

I need to write above code in every new root terminal to be able to use autocompletion.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Wandang
  • 271

2 Answers2

1

You need to add it to ~/.bashrc, not bash_profile, in this case... but you'll want to only apply it to interactive shells, to avoid taking time whenever you run a script:

case $- in
  *i*) # interactive shell
    source /etc/bash_completion;;
esac

You may need to add to /root/.bashrc for it to work as root... but why are you running a shell as root instead of using sudo for individual commands?

Random832
  • 10,666
  • Testing PS1 has nothing to do with interactive shells, actually. Some distributions ship with files that use that, but it's wrong. Interactive shells have i in their options in $- (even if it wasn't passed explicitly on the command line). – Gilles 'SO- stop being evil' Sep 28 '12 at 22:56
0

Put this line to ~/.bash_profile:

. /etc/bash_completion

daisy
  • 54,555
  • i had no bash profile, so i created it with your entry. this did not work for me. seems like i could not recover the entire /home/ (I accidently deleted it a few days back: http://unix.stackexchange.com/questions/49080/undo-rm-r-restore-data ). maybe i should just save data and resetup the machine. thanks for your answer thou! – Wandang Sep 28 '12 at 08:54