Skip to content

Commit 7855322

Browse files
committed
Init-App modular - first version for Windows
- utilize `$env.Path` on top level scope instead for persistence
1 parent 0d0eb96 commit 7855322

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

init-app.nu

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,45 +11,40 @@
1111
# init-app reset-env-path
1212
#
1313
# .NOTES
14-
# Not working on NuShell yet, hence moved to init.nu for now
1514
# Targeting apps i.e., choco, python (ML).
1615
# Required Env Vars:
1716
# - $pfiles_x64_dir
1817
#------------------------------------------------------------------------------
1918

2019
def main [
21-
app_name: string = 'reset-env-path' # Name of app for which to init
20+
app_name: string = 'reset-env-path' # Name of app for which to init
2221
] {
2322
print $"Init for app: ($app_name)"
24-
# ShellHome from config.nu isn't available here on win for some reason
25-
let ShellHome = "D:\\Code\\shell"
26-
let pfiles_x64_dir = "C:\\PFiles_x64\\choco"
2723

28-
print $"Current env Path: ($env.Path)"
24+
let pfiles_x64_dir = "C:\\PFiles_x64\\choco"
25+
let prior_env_path = $env.Path
2926

3027
match $app_name {
3128
'git' => {
3229
let git_path = ($pfiles_x64_dir | path join 'git' 'cmd')
33-
$env.Path = ($env.Path | append $git_path)
34-
# $env.Path = ($env.Path | append "C:\\PFiles_x64\\choco\\git\\cmd")
35-
print $"Added to PATH: ($git_path)"
30+
let path_with_git = ($prior_env_path | append $git_path)
31+
$path_with_git
3632
}
3733
'reset-env-path' => {
38-
# Example: Reset PATH to default
39-
$env.Path = ( [
34+
# Reset PATH to default
35+
[
4036
($env.SystemRoot | path join 'system32'),
4137
$env.SystemRoot,
4238
($env.SystemRoot | path join 'System32' 'Wbem'),
4339
($env.LOCALAPPDATA | path join 'Microsoft' 'WindowsApps'),
44-
$ShellHome,
4540
($env.SystemRoot | path join 'System32' 'OpenSSH'),
46-
($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0')
47-
])
41+
($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0'),
42+
$ShellHome
43+
]
4844
}
4945
_ => {
5046
print $"Invalid command line argument: ($app_name)"
47+
$prior_env_path
5148
}
5249
}
53-
54-
print $"Updated env Path: ($env.Path)"
5550
}

init.nu

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,14 @@ print $"NuShell ($env.NU_VERSION) on ($nu.os-info.name) ($nu.os-info.kernel_vers
5454
# - InitConsoleUI, and probably
5555
# - app specific adjustments that are coming from sdkman
5656

57-
# NuShell Env variables are scoped
58-
# TODO: check sourcing the init-app script here if not try use like a module
57+
# Nushell doesn't support persistent env.Path inside custom commands
58+
# Hence, utilize the method/custom command, yet, assign it here
59+
# resetEnvPath and `git add` support on Win below
5960
if ($nu.os-info.name == "windows") {
60-
print --no-newline "Init for app: reset-env-path, "
61+
print ""
6162

62-
$env.Path = ( [
63-
($env.SystemRoot | path join 'system32'),
64-
$env.SystemRoot,
65-
($env.SystemRoot | path join 'System32' 'Wbem'),
66-
($env.LOCALAPPDATA | path join 'Microsoft' 'WindowsApps'),
67-
$ShellHome,
68-
($env.SystemRoot | path join 'System32' 'OpenSSH'),
69-
($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0')
70-
])
71-
72-
print "git"
73-
let pfiles_x64_dir = "C:\\PFiles_x64\\choco"
74-
let git_path = ($pfiles_x64_dir | path join 'git' 'cmd')
75-
$env.Path = ($env.Path | append $git_path)
63+
source ./init-app.nu
64+
$env.Path = (main reset-env-path)
65+
$env.Path = (main git)
7666
}
77-
7867
print ""

0 commit comments

Comments
 (0)