bug-bash
[Top][All Lists]
Advanced

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

Re: Strange compgen behaviour


From: Mathias Dahl
Subject: Re: Strange compgen behaviour
Date: Wed, 23 Sep 2009 02:34:53 -0700 (PDT)
User-agent: G2/1.0

> It depends heavily on how the variables IFS and zf are set. From 'man bash':
>
> -W wordlist
>     The  wordlist is split using the characters in the IFS special
>     variable as delimiters, and each resultant word is expanded.
>     The possible completions are the members  of  the  resultant
>     list which match the word being completed.

I used a newline since the original listing comes from `find'.

> You didn't say how you assigned the variable zf. If you simply did
> zf=$(ls /home/mathias/Videos/movies/*), the "Brazil" line will be split
> into 4 words instead of 1. However, your output suggest that you somehow
> managed to combine all file names to a single word starting with
> Harry.Potter.

Yes, that could be the case.

> Try this: Choose a character which doesn't appear in any file name,
> e.g., ':'.
>
>      list=$(printf "%s:" /home/mathias/Videos/movies/*)
>      IFS=: compgen -W "$list" -- $zc

That works, thanks! However, I also want files from sub folders to be
found, so I use `find' to list them.

Here is my latest attempt, using the idea of setting IFS to `:':

_mm2() {
    local cur files
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    files=$(find /home/mathias/Videos/movies/ -iname '*.avi' -type f -
printf "%p:")
    OLDIFS=$IFS
    IFS=:
    COMPREPLY=($(compgen -W "${files}" -- ${cur}))
    IFS=$OLDIFS
}
complete -o filenames -F _mm2 mm

Looks like it should work but it does not. Typing mm<SPC><TAB> gives
the listing and completes all the way to the path, but if I add B
again it does not match Brazil.

Any ideas?


reply via email to

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