Skip to content

Idea for ability to optionally override default modules and scripts install path - Duscussion and contribution is welcome! #1673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ce4d559
Return path override if present
o-l-a-v Jul 13, 2024
166bf07
Make more robust
o-l-a-v Jul 13, 2024
37417de
Get empty/non-existent env variable is not expected to throw
o-l-a-v Jul 13, 2024
de08199
More robust
o-l-a-v Jul 13, 2024
acecb75
Expand, not resolve
o-l-a-v Jul 13, 2024
2713e4f
Add verbose message
o-l-a-v Jul 13, 2024
3556f80
Don't get paths twice
o-l-a-v Jul 13, 2024
f3abadd
Add newline before comments
o-l-a-v Jul 13, 2024
49db4bb
Remove empty newline
o-l-a-v Jul 14, 2024
802184e
Added new cmdlet
o-l-a-v Jul 14, 2024
a6352fe
"using System;" was written twice
o-l-a-v Jul 14, 2024
386bcf3
Only for Windows because env variables is very different on Unix + Ma…
o-l-a-v Jul 14, 2024
6ada4c6
Sort using alphabetically
o-l-a-v Jul 14, 2024
30bdf6a
Made code easier to navigate in VSCode
o-l-a-v Jul 14, 2024
3583604
Added ability to set the override env variable
o-l-a-v Jul 14, 2024
69863bb
Finished barebone functionality
o-l-a-v Jul 14, 2024
2d1ed6f
Simplified expression, thanks C# extension
o-l-a-v Jul 14, 2024
f451010
Treat -Path more like in Save-PSResource
o-l-a-v Jul 14, 2024
90ccdc9
Looks better this way IMO
o-l-a-v Jul 14, 2024
16339a1
Comment update
o-l-a-v Jul 14, 2024
398b2a6
Don't think ExpandEnvironmentVariables throws if some %VAR% does not …
o-l-a-v Jul 14, 2024
ec79901
Added -WhatIf support
o-l-a-v Jul 14, 2024
c80a398
Remove unneccessary "using"
o-l-a-v Jul 14, 2024
ba7b5f4
Fixed adding scripts dir to PATH
o-l-a-v Jul 14, 2024
ce7d0f7
PATH is named Path
o-l-a-v Jul 14, 2024
69c88ad
Big oops, set Path not PSModulePath for scripts dir
o-l-a-v Jul 14, 2024
8026053
Fixed verbose message
o-l-a-v Jul 14, 2024
853fb56
Simplify some more
o-l-a-v Jul 14, 2024
e5d145d
Return path override if present
o-l-a-v Jul 13, 2024
fb1d306
Make more robust
o-l-a-v Jul 13, 2024
7289dee
Get empty/non-existent env variable is not expected to throw
o-l-a-v Jul 13, 2024
76d75e2
More robust
o-l-a-v Jul 13, 2024
288edec
Expand, not resolve
o-l-a-v Jul 13, 2024
89f3dfc
Add verbose message
o-l-a-v Jul 13, 2024
9b4b60f
Don't get paths twice
o-l-a-v Jul 13, 2024
9e8617c
Add newline before comments
o-l-a-v Jul 13, 2024
02b79b7
Remove empty newline
o-l-a-v Jul 14, 2024
82e501c
Added new cmdlet
o-l-a-v Jul 14, 2024
4b02c09
"using System;" was written twice
o-l-a-v Jul 14, 2024
a86eae5
Only for Windows because env variables is very different on Unix + Ma…
o-l-a-v Jul 14, 2024
abb819e
Sort using alphabetically
o-l-a-v Jul 14, 2024
8ad86c5
Made code easier to navigate in VSCode
o-l-a-v Jul 14, 2024
92a72cf
Added ability to set the override env variable
o-l-a-v Jul 14, 2024
d067987
Finished barebone functionality
o-l-a-v Jul 14, 2024
8f2cc35
Simplified expression, thanks C# extension
o-l-a-v Jul 14, 2024
f278bb8
Treat -Path more like in Save-PSResource
o-l-a-v Jul 14, 2024
eabf85d
Looks better this way IMO
o-l-a-v Jul 14, 2024
8b1bdce
Comment update
o-l-a-v Jul 14, 2024
fc20175
Don't think ExpandEnvironmentVariables throws if some %VAR% does not …
o-l-a-v Jul 14, 2024
854e599
Added -WhatIf support
o-l-a-v Jul 14, 2024
2682b98
Remove unneccessary "using"
o-l-a-v Jul 14, 2024
e2e8d0b
Fixed adding scripts dir to PATH
o-l-a-v Jul 14, 2024
d51bdef
PATH is named Path
o-l-a-v Jul 14, 2024
3e243a4
Big oops, set Path not PSModulePath for scripts dir
o-l-a-v Jul 14, 2024
1b2bf32
Fixed verbose message
o-l-a-v Jul 14, 2024
be6d635
Simplify some more
o-l-a-v Jul 14, 2024
b0d7261
Merge branch 'install-path-override' of https://github.com/o-l-a-v/Po…
o-l-a-v Aug 21, 2024
c0f6dba
Merge branch 'master' into install-path-override
o-l-a-v Aug 21, 2024
9b84e89
Remove unneccessary using
o-l-a-v Aug 21, 2024
2f371a2
Merge branch 'master' into install-path-override
o-l-a-v Oct 23, 2024
71db23c
Format on save
o-l-a-v Oct 23, 2024
7cd3a1b
Removed unused "using"
o-l-a-v Oct 23, 2024
3b9ed21
Remove unused using and run formatting
o-l-a-v Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added -WhatIf support
  • Loading branch information
o-l-a-v committed Jul 14, 2024
commit ec79901912c5996f4b6674be5635366010bd843e
65 changes: 37 additions & 28 deletions src/code/SetPSResourceGetInstallPathOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,21 @@ protected override void ProcessRecord()
);
}
else {
Environment.SetEnvironmentVariable(
"PSResourceGetInstallPathOverride",
_path,
EnvScope
);
WriteVerbose(
String.Format(
"PSResourceGetInstallPathOverride in scope '{0}' was successfully set to: '{1}'",
EnvScope.ToString(),
_path
)
);
if (this.ShouldProcess($"Set environment variable PSResourceGetPathOverride in scope '{EnvScope} to '{_path}"))
{
Environment.SetEnvironmentVariable(
"PSResourceGetInstallPathOverride",
_path,
EnvScope
);
WriteVerbose(
String.Format(
"PSResourceGetInstallPathOverride in scope '{0}' was successfully set to: '{1}'",
EnvScope.ToString(),
_path
)
);
}
}

// Add install path override to PSModulePath
Expand All @@ -137,11 +140,14 @@ protected override void ProcessRecord()
);
if (String.IsNullOrEmpty(PSModulePath)) {
WriteVerbose(String.Format("PSModulePath in {0} context is empty.", EnvScope.ToString()));
System.Environment.SetEnvironmentVariable(
"PSModulePath",
_path,
EnvScope
);
if (this.ShouldProcess($"Set environment pariable 'PSModulePath' in scope '{EnvScope} to '{_path}"))
{
System.Environment.SetEnvironmentVariable(
"PSModulePath",
_path,
EnvScope
);
}
}
WriteVerbose(string.Format("Current value of PSModulePath in {0} context: '{1}'", EnvScope.ToString(), PSModulePath));
StringCollection PSModulePaths = new();
Expand All @@ -158,17 +164,20 @@ protected override void ProcessRecord()
EnvScope.ToString()
)
);
System.Environment.SetEnvironmentVariable(
"PSModulePath",
String.Format("{0};{1}", _path, PSModulePath),
EnvScope
);
WriteVerbose(
String.Format(
"Override install path was successfully added to PSModulePath for scope '{0}'.",
EnvScope.ToString()
)
);
if (this.ShouldProcess($"Add '{_path}' to environment pariable 'PSModulePath' in scope '{EnvScope}"))
{
System.Environment.SetEnvironmentVariable(
"PSModulePath",
String.Format("{0};{1}", _path, PSModulePath),
EnvScope
);
WriteVerbose(
String.Format(
"Override install path was successfully added to PSModulePath for scope '{0}'.",
EnvScope.ToString()
)
);
}
}
}

Expand Down