_zimfw_check_version() {
  if (( ${1} )); then
    if (( ${2} )); then
      # background check
      if [[ -w ${_zversion_target:h} ]]; then
        print -R ${${${(f)"$(GIT_HTTP_LOW_SPEED_LIMIT=1000 GIT_HTTP_LOW_SPEED_TIME=30 command git ls-remote --tags --refs --sort=-v:refname \
            https://github.com/zimfw/zimfw.git 'v*' 2>/dev/null)"}##*v}[1]} >! ${_zversion_target} &!
      fi
    else
      # foreground check
      local tags
      tags=$(command git ls-remote --tags --refs --sort=-v:refname https://github.com/zimfw/zimfw.git 'v*') || return 1
      >! ${_zversion_target} <<<${${${(f)tags}##*v}[1]} || return 1
    fi
  fi
  if [[ -f ${_zversion_target} ]]; then
    local -r zlatest_version=$(<${_zversion_target})
    if [[ -n ${zlatest_version} && ${_zversion} != ${zlatest_version} ]]; then
      _zimfw_print -u2 -R "${_zyellow}Latest zimfw version is ${_zbold}${zlatest_version}${_znormalyellow}. You're using version ${_zbold}${_zversion}${_znormalyellow}. Run ${_zbold}zimfw upgrade${_znormalyellow} to upgrade.${_znormal}"
      return 4
    fi
  fi
}
