activate.sh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #
  2. # This file must be used by invoking "source activate.sh" from the command line.
  3. # You cannot run it directly.
  4. # To exit from the environment this creates, execute the 'deactivate' function.
  5. _RED="\033[0;31m"
  6. _MAGENTA="\033[0;95m"
  7. _YELLOW="\033[0;33m"
  8. _RESET="\033[0m"
  9. # This detects if a script was sourced or invoked directly
  10. # See https://stackoverflow.com/a/28776166/2526265
  11. sourced=0
  12. if [ -n "$ZSH_EVAL_CONTEXT" ]; then
  13. case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
  14. THIS_SCRIPT="${0:-}"
  15. elif [ -n "$KSH_VERSION" ]; then
  16. [ "$(cd $(dirname -- $0) && pwd -P)/$(basename -- $0)" != "$(cd $(dirname -- ${.sh.file}) && pwd -P)/$(basename -- ${.sh.file})" ] && sourced=1
  17. THIS_SCRIPT="${0:-}"
  18. elif [ -n "$BASH_VERSION" ]; then
  19. (return 2>/dev/null) && sourced=1
  20. THIS_SCRIPT="$BASH_SOURCE"
  21. else # All other shells: examine $0 for known shell binary filenames
  22. # Detects `sh` and `dash`; add additional shell filenames as needed.
  23. case ${0##*/} in sh|dash) sourced=1;; esac
  24. THIS_SCRIPT="${0:-}"
  25. fi
  26. if [ $sourced -eq 0 ]; then
  27. printf "${_RED}This script cannot be invoked directly.${_RESET}\n"
  28. printf "${_RED}To function correctly, this script file must be sourced by calling \"source $0\".${_RESET}\n"
  29. exit 1
  30. fi
  31. deactivate () {
  32. # reset old environment variables
  33. if [ ! -z "${_OLD_PATH:-}" ] ; then
  34. export PATH="$_OLD_PATH"
  35. unset _OLD_PATH
  36. fi
  37. if [ ! -z "${_OLD_PS1:-}" ] ; then
  38. export PS1="$_OLD_PS1"
  39. unset _OLD_PS1
  40. fi
  41. # This should detect bash and zsh, which have a hash command that must
  42. # be called to get it to forget past commands. Without forgetting
  43. # past commands the $PATH changes we made may not be respected
  44. if [ -n "${BASH:-}" ] || [ -n "${ZSH_VERSION:-}" ] ; then
  45. hash -r 2>/dev/null
  46. fi
  47. unset DOTNET_ROOT
  48. unset DOTNET_MULTILEVEL_LOOKUP
  49. if [ ! "${1:-}" = "init" ] ; then
  50. # Remove the deactivate function
  51. unset -f deactivate
  52. fi
  53. }
  54. # Cleanup the environment
  55. deactivate init
  56. DIR="$( cd "$( dirname "$THIS_SCRIPT" )" && pwd )"
  57. _OLD_PATH="$PATH"
  58. # Tell dotnet where to find itself
  59. export DOTNET_ROOT="$DIR/.dotnet"
  60. # Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things
  61. export DOTNET_MULTILEVEL_LOOKUP=0
  62. # Put dotnet first on PATH
  63. export PATH="$DOTNET_ROOT:$PATH"
  64. # Set the shell prompt
  65. if [ -z "${DISABLE_CUSTOM_PROMPT:-}" ] ; then
  66. _OLD_PS1="$PS1"
  67. export PS1="(`basename \"$DIR\"`) $PS1"
  68. fi
  69. # This should detect bash and zsh, which have a hash command that must
  70. # be called to get it to forget past commands. Without forgetting
  71. # past commands the $PATH changes we made may not be respected
  72. if [ -n "${BASH:-}" ] || [ -n "${ZSH_VERSION:-}" ] ; then
  73. hash -r 2>/dev/null
  74. fi
  75. printf "${_MAGENTA}Enabled the .NET Core environment. Execute 'deactivate' to exit.${_RESET}\n"
  76. if [ ! -f "$DOTNET_ROOT/dotnet" ]; then
  77. printf "${_YELLOW}.NET Core has not been installed yet. Run $DIR/restore.sh to install it.${_RESET}\n"
  78. else
  79. printf "dotnet = $DOTNET_ROOT/dotnet\n"
  80. fi