Chet Ramey wrote:
Matthew Woehlke wrote:

Because "for some reason, non-trivial completions never seem to want to work for me"?

Sigh. Ok, after trying for entirely too long, this seems to be working:
completeme() {
  local i=0
  while read l; do
    COMPREPLY[$((++i))]="$l"
  done < <(
    cd /some/prefix
    w="${COMP_WORDS[1]}"
    if [ -n "$w" ]
      then compgen -d "$w"
      else compgen -d
    fi
  )
}
complete -F completeme cs

...and yet, seems entirely too difficult.

Maybe something like this?

foo()
{
        local -a a
        PREFIX=/usr/local

        builtin cd $PREFIX || {
        COMPREPLY=()
        return 1
    }
        a=( $(compgen -d "$2") )

        COMPREPLY=( "[EMAIL PROTECTED]/}" )

        builtin cd $OLDPWD
}

Doesn't this nuke $OLDPWD though? That's an annoying downside...

Ok, but why not just this?

foo() { COMPREPLY=( $(cd $KDE_SRC && compgen -d "$2") ); }

Heh. So much easier when I know I can do foo=( $(...stuff...) ) to turn lines into an array :-).

(The hoop-jumping to remove PREFIX seems unnecessary, compgen -d doesn't add it in the first place, at least not for me.

The difficulty is getting a trailing `/' -- readline won't add it, since
the completions are in a different directory.

I can live with that; more often than not I don't need it. Or I can just explicitly add a trailing '/'. What's more annoying is, can I tell bash not to add a space? (This seems like a relatively easy enhancement, like there should be some way to tell complete not to add a space, say by setting COMPADDSPACE=0 in the function.)

Why does 'compgen -d ""' produce no output? Shouldn't it produce the same output as 'compgen -d'?

Ummm...it does for me.

Well wtf, I swear it didn't before, but it's working now. I'm confused :-).

--
Matthew
Person A: It's an ISO standard.
Person B: ...And that means what?
  --mal (http://theangryadmin.blogspot.com/2008/04/future.html)



Reply via email to