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: Fri, 22 Aug 2008 18:30:03 -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:
I have a function 'cs' that roughly looks like 'cd /some/prefix/$*', that I would like to have completion for. Any tips? (For some reason, non-trivial completions never seem to want to work for me :-(.)

Why not write a shell function that prefixes the right directory to
the word to be completed, runs compgen, and strips the prefix from the
generated list of completions?

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.

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

--
Matthew
For great justice!! -- Captain (Zero Wing)





reply via email to

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