export __ENVRC_HOME__="${ENVRC_HOME:-"$HOME/.envrc.d"}"
load_envs() {
  for item in $(ls -A "${__ENVRC_HOME__}" 2>/dev/null)
  do
    . "${__ENVRC_HOME__}/$item"
    local __RESULT_CODE__=$?
    test 0 -eq "$__RESULT_CODE__" &&  (test -n "$ENVRC_DEBUG" && echo "loaded: [$item]" ; :) || echo "error: [$item]"
  done
}
load_envs

download_url() {
  URL=$1
  FILE=$2
  if command -v wget >/dev/null 2>&1; then
    local WGET_ARGS=("--no-check-certificate" "--timeout=10" "--tries=10")
    if test -n "$FILE"; then
      wget ${WGET_ARGS[@]} -O $FILE $URL
    else
      wget ${WGET_ARGS[@]} $URL
    fi
  elif command -v curl >/dev/null 2>&1; then
    local CURL_ARGS=("-m" "10" "--retry" "10" "-sSLk")
    if test -n "$FILE"; then
      curl ${CURL_ARGS[@]} -o $FILE $URL
    else
      curl ${CURL_ARGS[@]} -O $URL
    fi
  fi
}

envrc_install() {
  local __ENVRC__="${ENVRC:-"$HOME/.envrc"}"
  download_url https://apiv1.github.io/Shell/envrc "${__ENVRC__}"
  . "${__ENVRC__}"
echo '
Put it into your shell rc file:
    . '${__ENVRC__}'
'
}

__envrc_install__() {
  mkdir -p "${__ENVRC_HOME__}"
  cd "${__ENVRC_HOME__}"
  download_url $1
  cd -
  load_envs
}

richrc_install() {
  __envrc_install__ https://apiv1.github.io/Shell/richrc
}

tmuxrc_install() {
  __envrc_install__ https://apiv1.github.io/Shell/tmuxrc
}

dood_install() {
  __envrc_install__ https://apiv1.github.io/Docker/docker/docker.envrc
}

myvim_install() {
  __envrc_install__ https://apiv1.github.io/Docker/myvim/myvim.envrc
}

code_server_install() {
  __envrc_install__ https://apiv1.github.io/Docker/code-server/code-server.envrc
}

dict_install() {
  __envrc_install__ https://apiv1.github.io/Docker/node-dict/node-dict.envrc
}

z_install() {
  __envrc_install__ https://apiv1.github.io/z/z.sh
}

git_config_install() {
  download_url https://apiv1.github.io/Git/gitconfig ~/.gitconfig
}