Hi Peter, you were completely right! Now I have got some help at
stackoverflow, and it seems that helped solve this issue. There are four
things that seems must be in place to solve it:

1. compopt -o nospace
2. compopt -o filenames
3. Running compgen -f with an absolute path
4. Then postprocessing the results of compgen
  a) removing absoulte path prefix
  b) adding slashes after filenames

So here is minimal example (not handling quoting and spaces in file
names):

_compTest() {
    local cur tmp val
    cur="${COMP_WORDS[$COMP_CWORD]}"
    tmp=~/tmp/
    tmp_escaped=${tmp//\//\\\/}
    cur="$tmp$cur"    
    COMPREPLY=( $(compgen -f "$cur") )
    for ((i=0 ; i<${#COMPREPLY[@]}; i++ )) ; do
        val="${COMPREPLY[$i]}"
        [[ -d "$val" ]] && val="$val/"
        COMPREPLY[$i]="${val/$tmp_escaped/}"
    done    
}
complete -o filenames -o nospace -F _compTest aaa

Thanks again for excellent help!

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1394920

Title:
  complete -o filename can't be used with filenames relative to another
  directory to handle  space vs. trailing /

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1394920/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to