@@ -9,20 +9,67 @@ import { quoteArgs } from '../../execution/execUtils';
99import { traceError , traceInfo , traceVerbose } from '../../../common/logging' ;
1010import which from 'which' ;
1111import { ShellConstants } from '../../common/shellConstants' ;
12+ import { runCommand } from './utils' ;
13+ import { isWindows } from '../../../common/utils/platformUtils' ;
1214
1315async function isNuShellInstalled ( ) : Promise < boolean > {
1416 try {
15- await which ( 'nu' ) ;
17+ const binPath = await which ( 'nu' ) ;
18+ traceInfo ( `SHELL: Nu shell binary found at ${ binPath } ` ) ;
1619 return true ;
1720 } catch {
1821 return false ;
1922 }
2023}
2124
25+ async function getDefaultConfigPath ( ) : Promise < string | undefined > {
26+ try {
27+ const configPath = await runCommand ( 'nu -c $nu.default-config-dir' ) ;
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+
2236async function getNuShellProfile ( ) : Promise < string > {
23- const homeDir = os . homedir ( ) ;
24- // Nu shell configuration is typically at ~/.config/nushell/config.nu
25- return path . join ( homeDir , '.config' , 'nushell' , 'config.nu' ) ;
37+ const pathsToCheck : string [ ] = [ ] ;
38+
39+ const defaultConfigPath = await getDefaultConfigPath ( ) ;
40+ if ( defaultConfigPath ) {
41+ pathsToCheck . push ( path . join ( defaultConfigPath , 'config.nu' ) ) ;
42+ }
43+
44+ if ( isWindows ( ) ) {
45+ const appDataPath = process . env . APPDATA || path . join ( os . homedir ( ) , 'AppData' , 'Roaming' ) ;
46+ pathsToCheck . push ( path . join ( appDataPath , 'nushell' , 'config.nu' ) , path . join ( appDataPath , 'nu' , 'config.nu' ) ) ;
47+ }
48+
49+ pathsToCheck . push (
50+ path . join ( os . homedir ( ) , '.config' , 'nushell' , 'config.nu' ) ,
51+ path . join ( os . homedir ( ) , '.config' , 'nu' , 'config.nu' ) ,
52+ path . join ( os . homedir ( ) , '.nushell' , 'config.nu' ) ,
53+ path . join ( os . homedir ( ) , '.nu' , 'config.nu' ) ,
54+ ) ;
55+
56+ for ( const profilePath of pathsToCheck ) {
57+ if ( await fs . pathExists ( profilePath ) ) {
58+ traceInfo ( `SHELL: Nu shell profile found at ${ profilePath } ` ) ;
59+ return profilePath ;
60+ }
61+ }
62+
63+ // Nothing worked so return the default path
64+ if ( isWindows ( ) ) {
65+ const defaultPath = path . join ( os . homedir ( ) , 'AppData' , 'Roaming' , 'nushell' , 'config.nu' ) ;
66+ traceInfo ( `SHELL: Nu shell profile not found, using default path ${ defaultPath } ` ) ;
67+ return defaultPath ;
68+ }
69+
70+ const defaultPath = path . join ( os . homedir ( ) , '.config' , 'nushell' , 'config.nu' ) ;
71+ traceInfo ( `SHELL: Nu shell profile not found, using default path ${ defaultPath } ` ) ;
72+ return defaultPath ;
2673}
2774
2875const regionStart = '# >>> vscode python' ;
0 commit comments