This is the next discussion point in:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1394920
Suppose I have a folder ~/tmpwith some files and directories:
$ mkdir a; touch file1.txt; mkdir a/b; mkdir a/c; touch a/d; mkdir a/b/c
Now I am trying to complete the script to populate the file names in ~/tmp, but the parameter complete -o filenamesonly works correctly if the current directory ~/tmp.
See the link above for more background information. This, as I understand it:
$ cat setup
_compTest() {
local cur baseFolder
cur="${COMP_WORDS[$COMP_CWORD]}"
baseFolder=~/tmp
compopt -o nospace
COMPREPLY=( $(
cd "$baseFolder"
if [[ ${cur: -1} != "/" && -d $cur ]] ; then
echo "$cur/"
else
compgen -f "$cur"
fi
) )
}
complete -F _compTest aaa
Then I will send it:
$ . setup
and then I can do
$ aaa <tab><tab>
Problem 1: slashes are not added at the end of the list of names in the completion list (this is necessary to simplify individual directories from file names in the completion list)
2: aaa a/<tab><tab> a/b a/c a/d, a/ . b/ c/ d.