#!/bin/bash

_voxl_replay(){

	local OPTS=('--help --debug --path --number')

	COMPREPLY=()

	if [ "$COMP_CWORD" -eq 1 ]; then
		COMPREPLY=( $(compgen -W '${OPTS[@]}' -- ${COMP_WORDS[COMP_CWORD]}) )
		return 0
	fi

	local availableOpts=("${OPTS[@]}")

	case ${COMP_WORDS[COMP_CWORD-1]} in
		"-n" | "--number" )
			echo ""
			echo "Enter the number of log to open"
			echo -ne "${ECHO_PS1}${SET_BOLD}${CLR_BLU}$(dirs)${RESET_ALL}${CLR_LIT_YLW}$(__git_ps1 '(%s)')${RESET_ALL}\$"

			for i in $(seq 0 $COMP_CWORD); do
				echo -n " ${COMP_WORDS[i]}"
			done
			;;
		
		"-p" | "--path" )
			COMPREPLY=( $(compgen -d -- ${COMP_WORDS[COMP_CWORD]}) )
			return 0
			;;

		*)
			local availableOpts=("${OPTS[@]}")

			for i in $(seq 1 $COMP_CWORD);
			do	
				case "${COMP_WORDS[i]}" in 
					"-d"|"--debug") # debug
						availableOpts=("${availableOpts[@]/--debug}")
						;;
					"-h"|"--help") # help
						COMPREPLY=()
						return 0
						;;

			   	esac
			done
	esac
	return 0

}

complete -o filenames -F _voxl_replay voxl-replay
