@@ -23,6 +23,17 @@ async function isNuShellInstalled(): Promise<boolean> {
2323}
2424
2525async function getDefaultConfigPath ( ) : Promise < string | undefined > {
26+ try {
27+ const configPath = await runCommand ( isWindows ( ) ? 'nu -c $nu.config-path' : 'nu -c \\$nu.config-path' ) ;
28+
29+ return configPath ? configPath . trim ( ) : undefined ;
30+ } catch ( err ) {
31+ traceError ( `Failed to get default config path` , err ) ;
32+ return undefined ;
33+ }
34+ }
35+
36+ async function getDefaultConfigDir ( ) : Promise < string | undefined > {
2637 try {
2738 const configPath = await runCommand (
2839 isWindows ( ) ? 'nu -c $nu.default-config-dir' : 'nu -c \\$nu.default-config-dir' ,
@@ -38,12 +49,23 @@ async function getDefaultConfigPath(): Promise<string | undefined> {
3849async function getNuShellProfile ( ) : Promise < string > {
3950 const pathsToCheck : string [ ] = [ ] ;
4051
41- let defaultConfigPath = await getDefaultConfigPath ( ) ;
42- if ( defaultConfigPath ) {
43- defaultConfigPath = path . join ( defaultConfigPath , 'config.nu' ) ;
52+ const defaultConfigPath = await getDefaultConfigPath ( ) ;
53+ if ( defaultConfigPath && ( await fs . pathExists ( defaultConfigPath ) ) ) {
54+ // If the default config path exists, use it as the profile path
55+ traceInfo ( `SHELL: Nu shell profile found at ${ defaultConfigPath } ` ) ;
4456 return defaultConfigPath ;
4557 }
4658
59+ let defaultConfigDir = await getDefaultConfigDir ( ) ;
60+ if ( defaultConfigDir ) {
61+ defaultConfigDir = path . join ( defaultConfigDir , 'config.nu' ) ;
62+ if ( await fs . pathExists ( defaultConfigDir ) ) {
63+ traceInfo ( `SHELL: Nu shell profile found at ${ defaultConfigDir } ` ) ;
64+ return defaultConfigDir ;
65+ }
66+ return defaultConfigDir ;
67+ }
68+
4769 if ( isWindows ( ) ) {
4870 const appDataPath = process . env . APPDATA || path . join ( os . homedir ( ) , 'AppData' , 'Roaming' ) ;
4971 pathsToCheck . push ( path . join ( appDataPath , 'nushell' , 'config.nu' ) , path . join ( appDataPath , 'nu' , 'config.nu' ) ) ;
@@ -85,9 +107,9 @@ function getActivationContent(key: string): string {
85107 '' ,
86108 '' ,
87109 regionStart ,
88- `if (env | where name == "${ key } " | is-empty | not) ` ,
89- ` do $env.${ key } ` ,
90- 'end ' ,
110+ `if (not ($ env | get -i "${ key } " | is-empty)) { ` ,
111+ ` eval $env.${ key } ` ,
112+ '} ' ,
91113 regionEnd ,
92114 '' ,
93115 ] . join ( lineSep ) ;
0 commit comments