#!/usr/bin/env bash
# Summary: Calls `goenv-rehash` to rehash shims and also rehashes shell executable if shell is not 'fish'.
# Usage: goenv sh-rehash

set -e
[ -n "$GOENV_DEBUG" ] && set -x

# Provide goenv completions
if [ "$1" = "--complete" ]; then
  exec goenv-rehash --complete
fi

shell="$(basename "${GOENV_SHELL:-$SHELL}")"

# When goenv shell integration is enabled,
# delegate to goenv-rehash,
# then tell the shell to empty its command lookup cache.
goenv-rehash

case "$shell" in
fish )
  # NOTE: No rehash support
  ;;
* )
  echo "hash -r 2>/dev/null || true"
  ;;
esac
