Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I wrote a simple completion function that is doing what I want with one exception. Its completions are not expanded when I type M-* ("insert-completions") the way file completions are.

Is this an inherent limitation or something I can enable?

I just tried this on a different computer (with a slightly different version of BASH) and it worked there.

  • Works: 3.2.25(1)-release (Linux, CentOS 5.5)
  • No-Go: 3.2.48(1)-release (MacOS X 10.6.7)

Update: I am looking for an hypothesis that might explain the discrepancy between these two systems.

share|improve this question

1 Answer 1

I just added the following code from this web page to my .bash_profile:

_foo() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="--help --verbose --version"

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _foo foo

foo -- gets expanded to foo --help --verbose --version when pressing Meta-* in Terminal.app.

$ bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin10.0)
Copyright (C) 2007 Free Software Foundation, Inc.

So: I cannot reproduce with the same version of bashon Mac OS X 10.6.7. Did you change your environment after installation, e.g. installing third party unix stuff via Macports/Fink/Homebrew? Try using a fresh Terminal configuration by creating a new user account.

Make sure you actually are pressing Meta -- it's configurable in Terminal. If you don't set this option, there's no Meta:

enter image description here

Do other Meta shortcuts from readline work?


If this doesn't work: Since 10.7.0 Lion is not yet commercially available I suggest you just expect pre-release software to have bugs and report them to the proper site.

share|improve this answer
    
Yes, other Meta- work. This is Snow Leopard. That's just what "uname -a" produces. –  Randall Schulz May 6 '11 at 20:49
    
@Randall In your question, you wrote you use 10.7.0, which is the unreleased "Lion" scheduled for later this year. What do you press when Option is not your Meta key? You need to use an Esc sequence, i.e. first press Esc (don't hold), then press * afterwards. Also works for me. –  Daniel Beck May 7 '11 at 3:59
    
All I can tell you is that I'm running Snow Leopoard 10.6.7 and when I run "uname -a" it says the kernel is "Darwin Kernel Version 10.7.0". It is by no means a pre-release system. And as I said, Using Option for Meta, as I've configured it, will trigger insert-completions for file system-based completion. –  Randall Schulz May 8 '11 at 4:59
    
@Randall In that case, I suspect a problem with your completion function. I just put mine in .bash_profile. Try to do just that with the code I provided and see if it works then. –  Daniel Beck May 8 '11 at 9:06
    
@Randall Darwin follows a different versioning scheme than Mac OS X. Whenever Mac OS X gains a minor version (10.5 -> 10.6), Darwin gains a major version (9.x -> 10.x). Please edit your post to mention the correct Mac OS X version. –  Daniel Beck May 8 '11 at 9:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.