I have this bash completion file
#/etc/bash_completion.d/mycommand
_mycommand()
{
local cur
COMPREPLY=()
_init_completion || return
#Variable to hold the current word
cur="${COMP_WORDS[COMP_CWORD]}"
#array variable COMPREPLY
dirs=('Rootdir/
Secondrootdir/
Rootdir/Subdir/
Secondrootdir/Anothersubdir/
Secondrootdir/Thirdsubdir/
Secondrootdir/Anothersubdir/Subsubdir/'
)
COMPREPLY=($(compgen -W "$dirs" "$cur"))
}
#Assign the auto-completion function _mycommand for our command mycommand.
complete -F _mycommand mycommand
When I have multiple choice and hit TAB twice I see following:
$ mycommand Secondrootdir/
Secondrootdir/
Secondrootdir/Anothersubdir/
Secondrootdir/Anothersubdir/Subsubdir/
Secondrootdir/Thirdsubdir/
But I want to see only one-level deep subdirs of the current entered Secondrootdir
like this:
$ mycommand Secondrootdir/
Anothersubdir/ Thirdsubdir/
cd command does business well
$ cd Music/
kattymusic/ Playlists/ Relax/
But I can't understand how cd auto-completion works.
May anybody help me, please?