forked from pa-0/PwshScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit-app.nu
More file actions
96 lines (90 loc) · 3.33 KB
/
init-app.nu
File metadata and controls
96 lines (90 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env nu
#------------------------------------------------------------------------------
# .SYNOPSIS
# Initialize application-specific env path
#
# .DESCRIPTION
# Resets PATH to platform-specific defaults or adds application paths.
# Notes:
# - currently 2 apps: system default and git
# - system defaults with SDKMAN tools on Unix/Linux
# - On Windows, PFiles is currently used by git
#
# .PARAMETER app_name
# Application to initialize: 'git', 'reset-env-path' (default)
#
# .EXAMPLE
# source ./init-app.nu
# $env.Path = (main APP_NAME)
#
# .NOTES
# Platform-specific behavior:
# - Windows: Uses SystemRoot, PFiles_x64 paths (overlaps with choco)
# - Unix/Linux: Includes SDKMAN (Java, Kotlin, Gradle) + system paths
# - Unix/Linux: Warns if current PATH differs from expected baseline
# - Target apps: git, choco, python (ML) etc. more in future
#------------------------------------------------------------------------------
def --env init-app [
app_name: string = 'reset-env-path' # Name of app for which to init
] {
let pfiles_x64_dir = "C:\\PFiles_x64\\choco"
match $app_name {
# 'git' => managed via /usr/bin emulation
# not required in Unix, return default
# if ($nu.os-info.name != "windows") {
# # No changes needed for Unix
# } else {
# let git_path = ($pfiles_x64_dir | path join 'git' 'cmd')
# $env.Path = ($env.Path | append $git_path)
# }
# }
'reset-env-path' => {
# Reset PATH to platform-specific default
# Expected default system PATH for comparison
mut expected_system_path = [
"/usr/bin",
"/usr/sbin",
"/usr/local/bin",
($env.HOME | path join '.local' 'sdkman' 'candidates' 'kotlin' 'current' 'bin'),
($env.HOME | path join '.local' 'sdkman' 'candidates' 'java' 'current' 'bin'),
($env.HOME | path join '.local' 'sdkman' 'candidates' 'gradle' 'current' 'bin'),
($env.HOME | path join '.local' 'bin') # chezmoi
]
if ($nu.os-info.name != "windows") {
# backup of /etc/environment in configs dir
# Check if current PATH differs from expected
if ($env.Path != $expected_system_path) {
print "WARN: System environment PATH has changed from expected defaults:"
print $"Actual: ($env.Path)"
print ""
print $"Expected: ($expected_system_path)"
print ""
}
} else {
$expected_system_path = [
($env.SystemRoot | path join 'system32'),
$env.SystemRoot,
($env.SystemRoot | path join 'System32' 'Wbem'),
($env.LOCALAPPDATA | path join 'Microsoft' 'WindowsApps'),
($env.SystemRoot | path join 'System32' 'OpenSSH'),
# ($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0'),
"C:\\PFiles_x64\\bin" # /usr/bin emulation
]
}
# Assign to $env.Path instead of returning
$env.Path = ($expected_system_path | append $ShellHome)
print "Init: env.Path"
}
_ => {
error make {
msg: "Invalid argument",
label: {
text: $"Unknown app_name: ($app_name)",
span: (metadata $app_name).span
}
}
}
}
}
# This runs when sourced
init-app 'reset-env-path'