LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-22-2006, 02:51 PM   #1
extrasolar
Member
 
Registered: Feb 2004
Location: Northamptonshire, UK
Distribution: Windows XP, Arch Linux
Posts: 131

Rep: Reputation: 16
Tab completion with sudo


How do I enable tab completion when using sudo like on Ubuntu? I have no .bashrc file or /etc/bash.bashrc

Cheers.
 
Old 08-22-2006, 02:57 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
can you explain more clearly what you mean? tab completion is a standard default bash faeture so if that's your shell, you will have it enabled.
 
Old 08-22-2006, 03:16 PM   #3
extrasolar
Member
 
Registered: Feb 2004
Location: Northamptonshire, UK
Distribution: Windows XP, Arch Linux
Posts: 131

Original Poster
Rep: Reputation: 16
Sorry I meant for commands and applications. If I use sudo I have to type the full command and cannot use tab completion.
 
Old 08-22-2006, 03:26 PM   #4
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 32
When you hit tab in your shell, you get command completion and filename completion. For a contrived example, typing "lso<TAB>" at the beginning of the line will complete the command to "lsof", but "sudo lso<TAB>" tries to complete this argument as a file name, and often there is none starting with "lso".

My workaround is to complete first, then jump to the beginning (C-A) and add "sudo ". It helps to have the 3 directories {,/usr{,/local}}/sbin in your path as a normal user.

I know tcsh can be configured to very sophisticated context-sensitive completions; not sure about bash. That would be the fancy approach.
 
Old 08-22-2006, 03:28 PM   #5
statguy
Member
 
Registered: Sep 2004
Location: Ontario, Canada
Distribution: Slackware 14.2, current
Posts: 416

Rep: Reputation: 36
Do you mean that for example instead of typing

sudo /sbin/ifconfig

you would like to be able to type

sudo ifc[tab]

and have it expand to ifconfig?

I don't know the answer, just trying to help clarify the question.
 
Old 08-22-2006, 03:37 PM   #6
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116Reputation: 8116
You need to install the bash-completion package which is not part of stock Slackware but it is available in the /extra directory. A link to the package for Slackware 10.2 is here: http://slackware.osuosl.org/slackwar...sh-completion/

Eric
 
Old 08-22-2006, 03:44 PM   #7
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 79
For so-called "smart" tab-completion, most distros already supply some good rules (usually something like /etc/bash_completion). To put the rules in your startup, you generally source the file in ~/.bashrc or ~/.bash_profile or ~/.profile.

If you don't have a file /etc/bash_completion, you can create your own rules with the compgen and complete commands.

For example, for sudo to complete with executables, you could do:
Code:
complete -c sudo
Or you could think of more elaborate methods.
 
Old 08-22-2006, 03:46 PM   #8
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by osor
For so-called "smart" tab-completion, most distros already supply some good rules (usually something like /etc/bash_completion). To put the rules in your startup, you generally source the file in ~/.bashrc or ~/.bash_profile or ~/.profile.

If you don't have a file /etc/bash_completion, you can create your own rules with the compgen and complete commands.

For example, for sudo to complete with executables, you could do:
Code:
complete -c sudo
Or you could think of more elaborate methods.
/me continues to learn new commands.....
 
Old 08-22-2006, 03:46 PM   #9
Quigi
Member
 
Registered: Mar 2003
Location: Cambridge, MA, USA
Distribution: Ubuntu (Dapper and Heron)
Posts: 377

Rep: Reputation: 32
I should have read "man bash" before (so should everyone).

Extrasolar:
Use complete-command (M-!), i.e.,

sudo /usr/sbin/lso[M-!]

to complete it to "/usr/sbin/lsof". (And if /usr/sbin is in your path, you don't have to type it.)

And yes, bash has Programmable Completion (see man), which sounds nifty.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Command line tab completion reboots Suse 9.3 lmckinney SUSE / openSUSE 2 01-16-2006 05:29 AM
adding an option to a 'tab' completion + ls whatnoname Linux - Newbie 2 06-07-2005 08:32 AM
tab completion with scp fsbooks Linux - General 5 04-07-2005 04:13 PM
How can I turn on/install tab completion which I am so used to. jimdaworm *BSD 2 04-07-2005 12:25 AM
apt-get tab completion atheist Debian 6 06-11-2004 09:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration