Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Tab Autocompletion in the terminal. . .?

Tab Autocompletion in the terminal. . .?
Thread Tools
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
Jun 6, 2007, 08:23 PM
 
Hi All,

I'm interested in tab completion in the terminal. In most linux distributions you can type anything on a command line, and as long as it follows suit with the command it will tab complete. For instance:

1) If I type 'sudo xte' in Linux, I can simply press tab and it will autocomplete 'xterm'. However, in OS X, it seems to only want to autocomplete the first command and *ONLY* the first command ('sudo' in this case). This is annoying. It should perpetually autocomplete. I've tried every shell to no avail.

2) Also, in previous builds of OS X, I was able to type 'defaults read com.apple.' and it would autocomplete the "com"s. . .what has changed and why won't it do this anymore?


. . .any ideas as to how to remedy either of these?

Regards
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jun 6, 2007, 10:06 PM
 
Works exactly the same as for linux for me. Auto completion of the first 'word' on the line in the shell searches for commands (using your path environment variable). After the first 'word' it searches for files using the current working directory, or the directory you've typed in so far in the current 'word'.
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
Jun 6, 2007, 11:17 PM
 
Thank you, but that's not what I'm speaking of. I mean 'commands' and 'commands' specifically. For instance, let's compare using 'apt-get' in Linux to that of OS X (provided by either fink or darwinports). I can tab complete every single 'word' in Linux, regardless of the current working directory:


sudo apt-get install my_favorite_program


I can type 'su' TAB 'apt-g' TAB 'inst' TAB. . .et cetera, et cetera. Neither 'sudo' nor 'apt-get' (nor the 'install' option for apt-get) are in my pwd. Linux (say Ubuntu in this case) apparently references PATH as well. So I suppose I need to figure out a way to get terminal to reference PATH when tab completing.



. . .and still need a fix for the 'defaults read com.apple' stuff as well
     
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Jun 6, 2007, 11:20 PM
 
It's likely the default bash configuration is different in OS X. Perhaps copying over some of the settings will help.
     
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status: Offline
Reply With Quote
Jun 7, 2007, 12:02 AM
 
as I said, I get the exact same behaviour in both RedHat Linux and Mac OS X as what you describe for Mac OS X.

It is likely not an OS-specific issue, but rather a shell-specific, or even shell configuration issue, or perhaps an environment issue.
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
Jun 7, 2007, 12:06 AM
 
Originally Posted by Brass View Post
as I said, I get the exact same behaviour in both RedHat Linux and Mac OS X as what you describe for Mac OS X.

It is likely not an OS-specific issue, but rather a shell-specific, or even shell configuration issue, or perhaps an environment issue.

I don't doubt that it's a shell configuration issue. I just need to know *what* needs to be done. In this case GOOGLE simply hasn't been my friend.
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
Jun 7, 2007, 11:02 AM
 
Eh... The first word is autocompleted to any command in your path. The second is autocompleted to any filename in the current directory. That's the default behaviour, and I'm not aware of an OS that does it differently. What you're describing seems to be some sort of special treatment of sudo. Where did you see that? Could you please send me the config files if you find it, I'd love that feature.
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
Jun 7, 2007, 11:24 AM
 
Other distros do it, but give Ubuntu a try. There seems to be nothing special about any of the configuration files. I'm not sure what's going on. But, to rehash, I can do the following:


su[TAB] apt-ca[TAB] pkg[TAB]

and I'll get the following

sudo apt-cache pkgnames



. . .for whatever reason Ubuntu seems to support both multiple 'commands' (not just the first 'word' on a line) as well as options for certain commands. Still if the terminal in OS X can recognize files in the 'pwd', why can't one simply add PATH to the available type-ables (I'm sure that's a word somewhere) in the command line? Perhaps it is a special allowance for 'sudo'. Either way, I want it.
     
Clinically Insane
Join Date: Mar 2001
Location: yes
Status: Offline
Reply With Quote
Jun 7, 2007, 12:03 PM
 
how is your path set up? What do you get when you do a:

echo $PATH
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jun 7, 2007, 12:25 PM
 
Two things:

1. Your .inputrc
You should edit your .inputrc (creating it if necessary) to include the following lines:
[codex]# completion
set show-all-if-ambiguous on
set completion-ignore-case on

# history
"\e[A": history-search-backward
"\e[B": history-search-forward[/codex]

2. Bash completion extensions.

Run, don't walk, to Caliban.org and download the bash completion extensions there. This file contains the various per-application completions that you refer to. The installation is straightforward -- stick the file somewhere, edit the file so that it knows its own location, and add a line in .bashrc to source that file.
     
gberz3  (op)
Forum Regular
Join Date: Jun 2007
Status: Offline
Reply With Quote
Jun 7, 2007, 04:01 PM
 
Yeah, I'd actually come across Part 1 using Google. Part 2 doesn't seem to be of much use. What exactly does it do?
     
Grizzled Veteran
Join Date: Mar 2004
Status: Offline
Reply With Quote
Jun 9, 2007, 01:19 PM
 
Originally Posted by gberz3 View Post
If I type 'sudo xte' in Linux, I can simply press tab and it will autocomplete 'xterm'. However, in OS X, it seems to only want to autocomplete the first command and *ONLY* the first command ('sudo' in this case). This is annoying. It should perpetually autocomplete. I've tried every shell to no avail.

$ type -a xterm
-bash: type: xterm: not found

Um... something (like a command) has to actually EXIST
before auto-complete can do what it's supposed to do.
[maybe that wasn't the most universal example to post]

But, it looks like you may have a point after all.

I too will follow the suggestions posted by Mithras...
because "sudo chmo<tab>" also fails with a whimper.
[which is odd, since ^x-! prints chmod on a new line]
(Last edited by Hal Itosis; Jun 9, 2007 at 01:43 PM. )
-HI-
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jun 9, 2007, 02:01 PM
 
Part 2 does what you asked for! i.e. it defines autocompletes for a bunch of standard programs, so that your shell will know that after ssh you're going to type a hostname, etc.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:10 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2