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: Chet Ramey
Subject: Re: completing dir names for a certain path?
Date: Fri, 22 Aug 2008 21:38:40 -0400
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)

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
}

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

Why doesn't 'complete -C' work?

Programmable completion invokes the command specified with -C with three
arguments:

        $1 = command name
        $2 = word to be completed (possibly null)
        $3 = previous word

It's really designed to work with external commands or shell functions
that understand arguments, not command lists.  There's no other way for
an external command to get the word to be completed.


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

Ummm...it does for me.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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