#!/bin/zsh

### Determine bundle type:
### - ?       - unknown
### - empty   - empty string
### - file    - an existing file
### - dir     - an existing directory
### - path    - an non-existant path
### - relpath - a relative path
### - repo    - a git repo (user/repo format)
### - sshurl  - a git repo (SSH format)
### - url     - a git repo (URL format)
### - word    - a word
#function __antidote_bundle_type {
  emulate -L zsh; setopt local_options $_adote_funcopts
  local bundle=$1

  # Try to expand path bundles with '$' and '~' prefixes so that we get a more
  # granular result than 'path'.
  if [[ $bundle == '~/'* ]]; then
    bundle="${HOME}/${bundle#\~/*}"
  elif [[ $bundle == '$'* ]] && [[ $bundle != *'('* ]] && [[ $bundle != *';'* ]]; then
    bundle=$(eval print $bundle)
  fi

  # Determine the bundle type.
  local result
  if [[ -e "$bundle" ]]; then
    [[ -f $bundle ]] && result=file || result=dir
  elif [[ -z "${bundle// }" ]]; then
    result=empty
  else
    case "$bundle" in
      (/|~|'$')*)  result=path     ;;
      *://*)       result=url      ;;
      *@*:*/*)     result=sshurl   ;;
      *(:|@)*)     result='?'      ;;
      */*/*)       result=relpath  ;;
      */)          result=relpath  ;;
      */*)         result=repo     ;;
      *)           result=word     ;;
    esac
  fi

  typeset -g REPLY=$result
  print $result
#}
