# based on example from https://stackoverflow.com/questions/40333916/bash-tab-filename-completion-on-all-sub-folders
_comp_osgi_install () {
    local glob_flag
    if shopt -q globstar; then
        glob_flag=0
    else
        glob_flag=1
        shopt -s globstar
    fi

    # $2 is the word being completed
    local cur=$2

    # Loop over all files and directories in the current and all subdirectories
    local fname
    for fname in "$cur"**/*.jar; do
        # Only add files
        if [[ -f "$fname" ]]; then
            if [[ ! "$fname" =~ "-sources.jar" ]]; then
              COMPREPLY+=("$fname");
            fi
        fi
    done
    
    # Set globstar back to previous value if necessary
    if (( glob_flag == 1 )); then
        shopt -u globstar
    fi
    return 0;
}

complete -F _comp_osgi_install -o dirnames osgi-install

