You are not logged in.

#1 2008-03-18 04:34:14

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

[SOLVED] sudo & bash completion

I have trouble with bash completion and sudo.  e.g. if I type "shut" and hit tab the "shutdown" get autocompleted.  However, "sudo shut" <tab> does not work.  Any ideas?

Last edited by Allan (2008-03-18 04:55:05)

Offline

#2 2008-03-18 04:46:31

hacosta
Member
From: Mexico
Registered: 2006-10-22
Posts: 423

Re: [SOLVED] sudo & bash completion

add this to your .bashrc

complete -cf sudo

Offline

#3 2008-03-18 04:54:47

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: [SOLVED] sudo & bash completion

Thanks.  that fixed it!

Offline

#4 2008-05-27 11:42:36

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: [SOLVED] sudo & bash completion

I just noticed that adding

complete -cf sudo

to ~/.bashrc breaks completion. As user

$ cd .i
.icons/    .inkscape/ .inputrc   .inputrc~  .irssi/

Who wants to cd to a file? Files are not listed if you remove 'complete -cf sudo' line. Any other way to include the sudo to completion?

Offline

#5 2008-05-27 12:02:22

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,385
Website

Re: [SOLVED] sudo & bash completion

Edit:  Don't you get that even without this line...  I just tested both and it seems to happen.

Last edited by Allan (2008-05-27 12:13:13)

Offline

#6 2008-05-27 12:46:20

Abelian
Member
Registered: 2008-04-23
Posts: 63

Re: [SOLVED] sudo & bash completion

I thought bash completion was dumb, ie it had no concept of the arguments before in completing a filename. It would be neat if it did though!

Offline

#7 2008-05-27 16:38:12

Purch
Member
From: Finland
Registered: 2006-02-23
Posts: 229

Re: [SOLVED] sudo & bash completion

hmm, it worked in ssh connection and now I tested it

$ ssh localhost
$ cd .i
.icons/    .inkscape/ .irssi/

So this is related to ssh then. But still weird and it is not affected by 'complete -cf sudo' line.

Last edited by Purch (2008-05-27 16:39:03)

Offline

#8 2008-05-27 16:55:06

Ramses de Norre
Member
From: Leuven - Belgium
Registered: 2007-03-27
Posts: 1,289

Re: [SOLVED] sudo & bash completion

zsh seems to have this clever auto-complete, it doesn't propose files to me on completing cd.

Offline

#9 2008-12-08 11:46:07

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [SOLVED] sudo & bash completion

hacosta wrote:

add this to your .bashrc

complete -cf sudo

Does anyone know the zsh equivalent for this?


ᶘ ᵒᴥᵒᶅ

Offline

#10 2008-12-08 13:55:49

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: [SOLVED] sudo & bash completion

For me, bash doesn't try to cd into files either with bash completion.

Offline

#11 2008-12-08 17:47:20

Dieter@be
Forum Fellow
From: Belgium
Registered: 2006-11-05
Posts: 2,001
Website

Re: [SOLVED] sudo & bash completion

Abelian wrote:

I thought bash completion was dumb, ie it had no concept of the arguments before in completing a filename. It would be neat if it did though!

Maybe you mean bash' tab completion.
- tab completion is the built-in tab completion in bash (and other shells)
- bash completion is an additional feature for bash (eg package bash-completion ).  I'm not sure if it's installed by default


< Daenyth> and he works prolifically
4 8 15 16 23 42

Offline

#12 2008-12-08 19:39:28

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: [SOLVED] sudo & bash completion

What's strange for me is it previously worked in .bashrc. Then it just sort of stopped. Now I have it wrapped in .bashrc and it works:

if [ "$PS1" ]; then
    complete -cf sudo
fi

Offline

#13 2008-12-11 22:53:46

litemotiv
Forum Fellow
Registered: 2008-08-01
Posts: 5,026

Re: [SOLVED] sudo & bash completion

litemotiv wrote:
hacosta wrote:

add this to your .bashrc

complete -cf sudo

Does anyone know the zsh equivalent for this?

Actually, i meant sudo completion when going back in the zsh history, but now i'm getting more offtopic.. hmm


ᶘ ᵒᴥᵒᶅ

Offline

#14 2008-12-12 19:59:19

Nezmer
Member
Registered: 2008-10-24
Posts: 559
Website

Re: [SOLVED] sudo & bash completion

Is there a way to enable bash completion with aliases .
I use 'Q' as an alias for 'pacman -Q' .

In zsh  :
$ Q lx (then tab)

$ Q lx
lxappearance    lxlauncher      lxrandr         lxsplit         lxterminal      
lxde-common     lxpanel         lxsession-lite  lxtask

'completion works '

In bash :
$ pacman -Q lx (then 2 tabs)

$ pacman -Q lx
lxappearance    lxlauncher      lxrandr         lxsplit         lxterminal      
lxde-common     lxpanel         lxsession-lite  lxtask

'completion works '
but with :
$ Q lx (then 2 tabs)
'It doesn't work'


English is not my native language .

Offline

#15 2020-02-24 01:26:30

alaskanarcher
Member
Registered: 2016-04-30
Posts: 50

Re: [SOLVED] sudo & bash completion

hacosta wrote:

add this to your .bashrc

complete -cf sudo

At the risk of necro-bumping, I want to add a comment that this is completely incorrect. This thread led me astray. The above command will prevent bash from using the correct completion for commands that follow sudo. It will instead try suggest files as the completion for any commands that follow sudo. See this stack overflow answer.

Offline

#16 2020-02-24 05:16:00

Alad
Wiki Admin/IRC Op
From: Bagelstan
Registered: 2014-05-04
Posts: 2,412
Website

Re: [SOLVED] sudo & bash completion

"the risk"? You've just made a new record by reviving a 12-year old thread.


Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby

Offline

#17 2020-02-24 06:01:36

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,645

Re: [SOLVED] sudo & bash completion

Closing this old thread.

Offline

Board footer

Powered by FluxBB