11#!/usr/bin/env nu
22#------------------------------------------------------------------------------
33# .SYNOPSIS
4- # Initialize Specified Application
4+ # Initialize application-specific env path
5+ #
56# .DESCRIPTION
6- # TODO: Add Linux support (remove ~/bin when it doesn't exist)
7- # Initializes shell/env for application
8- # rewrite of pwsh/Init-App.ps1 *
7+ # Resets PATH to platform-specific defaults or adds application paths.
8+ # Notes:
9+ # - currently 2 apps: system default and git
10+ # - system defaults with SDKMAN tools on Unix/Linux
11+ # - On Windows, PFiles is currently used by git
12+ #
13+ # .PARAMETER app_name
14+ # Application to initialize: 'git', 'reset-env-path' (default)
915#
1016# .EXAMPLE
11- # init-app reset-env-path
17+ # source ./init-app.nu
18+ # $env.Path = (main APP_NAME)
1219#
1320# .NOTES
14- # Targeting apps i.e., choco, python (ML).
15- # Required Env Vars:
16- # - $pfiles_x64_dir
21+ # Platform-specific behavior:
22+ # - Windows: Uses SystemRoot, PFiles_x64 paths (overlaps with choco)
23+ # - Unix/Linux: Includes SDKMAN (Java, Kotlin, Gradle) + system paths
24+ # - Unix/Linux: Warns if current PATH differs from expected baseline
25+ # - Target apps: git, choco, python (ML) etc. more in future
1726#------------------------------------------------------------------------------
1827
1928def main [
@@ -26,22 +35,55 @@ def main [
2635
2736 match $app_name {
2837 ' git' => {
29- let git_path = ($pfiles_x64_dir | path join ' git' ' cmd' )
30- let path_with_git = ($prior_env_path | append $git_path )
31- $path_with_git
38+ # not required in Unix, return default
39+ if ($nu .os-info.name != " windows" ) {
40+ $prior_env_path
41+ } else {
42+ let git_path = ($pfiles_x64_dir | path join ' git' ' cmd' )
43+ let path_with_git = ($prior_env_path | append $git_path )
44+ $path_with_git
45+ }
3246 }
3347 ' reset-env-path' => {
34- # Reset PATH to default
35- [
36- ($env .SystemRoot | path join ' system32' ),
37- $env .SystemRoot ,
38- ($env .SystemRoot | path join ' System32' ' Wbem' ),
39- ($env .LOCALAPPDATA | path join ' Microsoft' ' WindowsApps' ),
40- ($env .SystemRoot | path join ' System32' ' OpenSSH' ),
41- # ($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0'),
42- " C:\\ PFiles_x64\\ bin" , # /usr/bin emulation
43- $ShellHome
44- ]
48+ # Reset PATH to platform-specific default
49+ if ($nu .os-info.name != " windows" ) {
50+ # backup of /etc/environment, pop_os 10-03-2025
51+ # $ cat /etc/environment
52+ # PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
53+
54+ # Expected default system PATH for comparison
55+ let expected_system_path = [
56+ " /usr/bin" ,
57+ " /usr/sbin" ,
58+ " /usr/local/bin" ,
59+ " /home/atiq/.local/sdkman/candidates/kotlin/current/bin" ,
60+ " /home/atiq/.local/sdkman/candidates/java/current/bin" ,
61+ " /home/atiq/.local/sdkman/candidates/gradle/current/bin"
62+ ]
63+
64+ # Check if current PATH differs from expected
65+ if ($env .Path != $expected_system_path ) {
66+ print " WARN: System environment PATH has changed from expected defaults:"
67+ print $" Actual: ($env .Path )"
68+ print " "
69+ print $" Expected: ($expected_system_path )"
70+ print " "
71+ }
72+
73+ # return standard system path with our shell's dir appended
74+ ($expected_system_path | append $ShellHome )
75+ } else {
76+ [
77+ ($env .SystemRoot | path join ' system32' ),
78+ $env .SystemRoot ,
79+ ($env .SystemRoot | path join ' System32' ' Wbem' ),
80+ ($env .LOCALAPPDATA | path join ' Microsoft' ' WindowsApps' ),
81+ ($env .SystemRoot | path join ' System32' ' OpenSSH' ),
82+ # ($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0'),
83+ " C:\\ PFiles_x64\\ bin" , # /usr/bin emulation
84+ $ShellHome
85+ ]
86+ }
4587 }
4688 _ => {
4789 print $" Invalid command line argument: ($app_name )"
0 commit comments