#!/usr/bin/env osh
# TODO  not yet working so just hardcode the function
# source <(example _carapace oil)
_example_completion() {
  local compline="${COMP_LINE:0:${COMP_POINT}}"
  local IFS=$'\n'
  mapfile -t COMPREPLY < <(echo "$compline" | sed -e "s/ \$/ ''/" -e 's/"/\"/g' | xargs example _carapace oil "_")
  [[ "${COMPREPLY[@]}" == "" ]] && COMPREPLY=() # fix for mapfile creating a non-empty array from empty command output
  [[ ${COMPREPLY[0]} == *[/=@:.,] ]] && compopt -o nospace
}

 COMP_LINE="$1"
 COMP_POINT=${#1}
 COMP_WORDS=($COMP_LINE'')
 COMP_CWORD=$((${#COMP_WORDS[@]}-1))
 
 _example_completion
 ( IFS=$'\n'; echo "${COMPREPLY[*]}" )
