Skip to content

Commit 31757a8

Browse files
committed
Simplify init.nu
- init-app.nu sourcing works to persistently modify env.Path - git managed via init-app.nu disabled for now - minor comments update / clean up
1 parent 53ac94a commit 31757a8

File tree

2 files changed

+33
-53
lines changed

2 files changed

+33
-53
lines changed

init-app.nu

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,37 @@
2525
# - Target apps: git, choco, python (ML) etc. more in future
2626
#------------------------------------------------------------------------------
2727

28-
def main [
28+
def --env init-app [
2929
app_name: string = 'reset-env-path' # Name of app for which to init
3030
] {
3131
print $"Init for app: ($app_name)"
3232

3333
let pfiles_x64_dir = "C:\\PFiles_x64\\choco"
34-
let prior_env_path = $env.Path
3534

3635
match $app_name {
37-
'git' => {
36+
# 'git' => managed via /usr/bin emulation
3837
# 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-
}
46-
}
38+
# if ($nu.os-info.name != "windows") {
39+
# # No changes needed for Unix
40+
# } else {
41+
# let git_path = ($pfiles_x64_dir | path join 'git' 'cmd')
42+
# $env.Path = ($env.Path | append $git_path)
43+
# }
44+
# }
4745
'reset-env-path' => {
4846
# Reset PATH to platform-specific default
47+
# Expected default system PATH for comparison
48+
mut expected_system_path = [
49+
"/usr/bin",
50+
"/usr/sbin",
51+
"/usr/local/bin",
52+
"/home/atiq/.local/sdkman/candidates/kotlin/current/bin",
53+
"/home/atiq/.local/sdkman/candidates/java/current/bin",
54+
"/home/atiq/.local/sdkman/candidates/gradle/current/bin"
55+
]
56+
4957
if ($nu.os-info.name != "windows") {
5058
# backup of /etc/environment in configs dir
51-
# Expected default system PATH for comparison
52-
let expected_system_path = [
53-
"/usr/bin",
54-
"/usr/sbin",
55-
"/usr/local/bin",
56-
"/home/atiq/.local/sdkman/candidates/kotlin/current/bin",
57-
"/home/atiq/.local/sdkman/candidates/java/current/bin",
58-
"/home/atiq/.local/sdkman/candidates/gradle/current/bin"
59-
]
60-
6159
# Check if current PATH differs from expected
6260
if ($env.Path != $expected_system_path) {
6361
print "WARN: System environment PATH has changed from expected defaults:"
@@ -66,25 +64,28 @@ def main [
6664
print $"Expected: ($expected_system_path)"
6765
print ""
6866
}
69-
70-
# return standard system path with our shell's dir appended
71-
($expected_system_path | append $ShellHome)
7267
} else {
73-
[
68+
$expected_system_path = [
7469
($env.SystemRoot | path join 'system32'),
7570
$env.SystemRoot,
7671
($env.SystemRoot | path join 'System32' 'Wbem'),
7772
($env.LOCALAPPDATA | path join 'Microsoft' 'WindowsApps'),
7873
($env.SystemRoot | path join 'System32' 'OpenSSH'),
7974
# ($env.SystemRoot | path join 'System32' 'WindowsPowerShell' 'v1.0'),
80-
"C:\\PFiles_x64\\bin", # /usr/bin emulation
81-
$ShellHome
75+
"C:\\PFiles_x64\\bin" # /usr/bin emulation
8276
]
8377
}
78+
79+
# Assign to $env.Path instead of returning
80+
$env.Path = ($expected_system_path | append $ShellHome)
8481
}
8582
_ => {
8683
print $"Invalid command line argument: ($app_name)"
87-
$prior_env_path
84+
# No change to Path for invalid arguments
8885
}
8986
}
90-
}
87+
}
88+
89+
90+
# This runs when sourced
91+
init-app 'reset-env-path'

init.nu

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,44 +57,23 @@ use std/dirs
5757

5858
# Navigate to shell home
5959
cd $ShellHome
60+
6061
# Show welcome
6162
print $"Welcome to (ansi green)Matrix Terminal(ansi reset)"
6263
print $"NuShell ($env.NU_VERSION) on ($nu.os-info.name) ($nu.os-info.kernel_version)"
63-
6464
print ""
6565

66+
# Seems to have some sort support of persistent env.Path inside custom commands
6667
source ./init-app.nu
67-
# print $"Path: (main reset-env-path)"
68-
$env.Path = (main reset-env-path)
69-
$env.Path = (main git)
70-
7168

7269
# Porting tasks TODO
7370
# - InitConsoleUI, and probably
74-
# - app specific adjustments that are coming from sdkman
7571

76-
# Nushell doesn't support persistent env.Path inside custom commands
77-
# Hence, utilize the method/custom command, yet, assign it here
78-
# resetEnvPath and `git add` support on Win below
7972
if ($nu.os-info.name == "windows") {
8073
source ./win/init.nu
8174
} else {
8275
# ssh initialization
8376
source ./ssh-init.nu
8477
}
8578

86-
# NuShell vars don't persist when scripts like .\fs-helper.nu are invoked on Win
87-
# However, env vars seem to persist
88-
# print $"Env Debug: ($env.PFilesX64Dir)"
89-
90-
# OS dependent inits for same instructions, differnet invocation syntax
91-
# since windows nushell keeps throwing error
92-
if ($nu.os-info.name == "windows") {
93-
# TODO: try following on windows, if it works might as well generalize
94-
# nu ./fs-helper.nu
95-
# this is separately invoked on windows since it throws an error
96-
.\fs-helper.nu
97-
} else {
98-
# WS text file init
99-
./fs-helper.nu
100-
}
79+
fs-helper.nu

0 commit comments

Comments
 (0)