Skip to content

Commit 0a72aee

Browse files
authored
Add activate scripts
These put the local `dotnet` on the path so you can use it normally PowerShell: . .\activate.ps1 macOS/Linux: source activate.sh
1 parent 647d15e commit 0a72aee

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

Diff for: activate.ps1

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# This file must be used by invoking ". .\activate.ps1" from the command line.
3+
# You cannot run it directly.
4+
# To exit from the environment this creates, execute the 'deactivate' function.
5+
#
6+
7+
function deactivate ([switch]$init) {
8+
9+
# reset old environment variables
10+
if (Test-Path variable:_OLD_PATH) {
11+
$env:PATH = $_OLD_PATH
12+
Remove-Item variable:_OLD_PATH
13+
}
14+
15+
if (test-path function:_old_prompt) {
16+
Set-Item Function:prompt -Value $function:_old_prompt -ea ignore
17+
remove-item function:_old_prompt
18+
}
19+
20+
Remove-Item env:DOTNET_ROOT -ea ignore
21+
Remove-Item env:DOTNET_MULTILEVEL_LOOKUP -ea ignore
22+
if (-not $init) {
23+
# Remove the deactivate function
24+
Remove-Item function:deactivate
25+
}
26+
}
27+
28+
# Cleanup the environment
29+
deactivate -init
30+
31+
$_OLD_PATH = $env:PATH
32+
# Tell dotnet where to find itself
33+
$env:DOTNET_ROOT = "$PSScriptRoot\.dotnet"
34+
# Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things
35+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
36+
# Put dotnet first on PATH
37+
$env:PATH = "${env:DOTNET_ROOT};${env:PATH}"
38+
39+
# Set the shell prompt
40+
if (-not $env:DISABLE_CUSTOM_PROMPT) {
41+
$function:_old_prompt = $function:prompt
42+
function dotnet_prompt {
43+
# Add a prefix to the current prompt, but don't discard it.
44+
write-host "($( split-path $PSScriptRoot -leaf )) " -nonewline
45+
& $function:_old_prompt
46+
}
47+
48+
Set-Item Function:prompt -Value $function:dotnet_prompt -ea ignore
49+
}
50+
51+
Write-Host -f Magenta "Enabled the .NET Core environment. Execute 'deactivate' to exit."
52+
if (-not (Test-Path "${env:DOTNET_ROOT}\dotnet.exe")) {
53+
Write-Host -f Yellow ".NET Core has not been installed yet. Run $PSScriptRoot\restore.cmd to install it."
54+
}
55+
else {
56+
Write-Host "dotnet = ${env:DOTNET_ROOT}\dotnet.exe"
57+
}

Diff for: activate.sh

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
6+
_MAGENTA="\033[0;95m"
7+
_YELLOW="\033[0;33m"
8+
_RESET="\033[0m"
9+
10+
deactivate () {
11+
12+
# reset old environment variables
13+
if [ ! -z "${_OLD_PATH:-}" ] ; then
14+
export PATH="$_OLD_PATH"
15+
unset _OLD_PATH
16+
fi
17+
18+
if [ ! -z "${_OLD_PS1:-}" ] ; then
19+
export PS1="$_OLD_PS1"
20+
unset _OLD_PS1
21+
fi
22+
23+
# This should detect bash and zsh, which have a hash command that must
24+
# be called to get it to forget past commands. Without forgetting
25+
# past commands the $PATH changes we made may not be respected
26+
if [ -n "${BASH:-}" ] || [ -n "${ZSH_VERSION:-}" ] ; then
27+
hash -r 2>/dev/null
28+
fi
29+
30+
unset DOTNET_ROOT
31+
unset DOTNET_MULTILEVEL_LOOKUP
32+
if [ ! "${1:-}" = "init" ] ; then
33+
# Remove the deactivate function
34+
unset -f deactivate
35+
fi
36+
}
37+
38+
# Cleanup the environment
39+
deactivate init
40+
41+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
42+
_OLD_PATH="$PATH"
43+
# Tell dotnet where to find itself
44+
export DOTNET_ROOT="$DIR/.dotnet"
45+
# Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things
46+
export DOTNET_MULTILEVEL_LOOKUP=0
47+
# Put dotnet first on PATH
48+
export PATH="$DOTNET_ROOT:$PATH"
49+
50+
# Set the shell prompt
51+
if [ -z "${DISABLE_CUSTOM_PROMPT:-}" ] ; then
52+
_OLD_PS1="$PS1"
53+
export PS1="(`basename \"$DIR\"`) $PS1"
54+
fi
55+
56+
# This should detect bash and zsh, which have a hash command that must
57+
# be called to get it to forget past commands. Without forgetting
58+
# past commands the $PATH changes we made may not be respected
59+
if [ -n "${BASH:-}" ] || [ -n "${ZSH_VERSION:-}" ] ; then
60+
hash -r 2>/dev/null
61+
fi
62+
63+
echo "${_MAGENTA}Enabled the .NET Core environment. Execute 'deactivate' to exit.${_RESET}"
64+
65+
if [ ! -f "$DOTNET_ROOT/dotnet" ]; then
66+
echo "${_YELLOW}.NET Core has not been installed yet. Run $DIR/restore.sh to install it.${_RESET}"
67+
else
68+
echo "dotnet = $DOTNET_ROOT/dotnet"
69+
fi

0 commit comments

Comments
 (0)