bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: completing dir names for a certain path?


From: Matthew Woehlke
Subject: Re: completing dir names for a certain path?
Date: Mon, 25 Aug 2008 10:42:27 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.16) Gecko/20080723 Fedora/2.0.0.16-1.fc9 Thunderbird/2.0.0.16 Mnenhy/0.7.5.0

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=( "address@hidden/}" )

        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

[Prev in Thread] Current Thread [Next in Thread]