_subsh() 
{
	local cur prev opts profiles
	COMPREPLY=()
	cur="${COMP_WORDS[COMP_CWORD]}"
	prev="${COMP_WORDS[COMP_CWORD-1]}"

	if [ $COMP_CWORD -eq 1 ]; then
		opts="init list create enter delete deinit"
	elif [ $COMP_CWORD -eq 2 ]; then
		if [ "$prev" = "enter" ] || [ "$prev" = "delete" ]; then
			profiles=()
			for f in ~/.subsh/*; do
				[ -d "$f" ] || continue
				profiles+=($(basename $f))
			done
			opts=${profiles[@]}
		fi
	fi

	COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
	return 0
}

complete -F _subsh subsh
