@@ -24,31 +24,31 @@ export function activate(context: vscode.ExtensionContext) {
24
24
provideTerminalProfile (
25
25
token : vscode . CancellationToken
26
26
) : vscode . ProviderResult < vscode . TerminalProfile > {
27
+ const which = require ( "which" ) ;
27
28
const path = require ( "path" ) ;
28
- const fs = require ( "fs" ) ;
29
- const glob = require ( "glob" ) ;
30
- const os = require ( "os" ) ;
31
29
30
+ const PATH_FROM_ENV = process . env [ "PATH" ] ;
32
31
const pathsToCheck = [
32
+ PATH_FROM_ENV ,
33
33
// cargo install location
34
- "~/.cargo/bin/nu" ,
35
- "~/.cargo/bin/nu.exe" ,
34
+ ( process . env [ "CARGO_HOME" ] || "~/.cargo" ) + "/bin" ,
36
35
37
36
// winget on Windows install location
38
- "c:\\program files\\nu\\bin\\nu.exe " ,
37
+ "c:\\program files\\nu\\bin" ,
39
38
// just add a few other drives for fun
40
- "d:\\program files\\nu\\bin\\nu.exe " ,
41
- "e:\\program files\\nu\\bin\\nu.exe " ,
42
- "f:\\program files\\nu\\bin\\nu.exe " ,
39
+ "d:\\program files\\nu\\bin" ,
40
+ "e:\\program files\\nu\\bin" ,
41
+ "f:\\program files\\nu\\bin" ,
43
42
44
43
// SCOOP:TODO
45
44
// all user installed programs and scoop itself install to
46
45
// c:\users\<user>\scoop\ unless SCOOP env var is set
47
46
// globally installed programs go in
48
47
// c:\programdata\scoop unless SCOOP_GLOBAL env var is set
49
48
// scoop install location
50
- "~/scoop/apps/nu/*/nu.exe" ,
51
- "~/scoop/shims/nu.exe" ,
49
+ // SCOOP should already set up the correct `PATH` env var
50
+ //"~/scoop/apps/nu/*/nu.exe",
51
+ //"~/scoop/shims/nu.exe",
52
52
53
53
// chocolatey install location - same as winget
54
54
// 'c:\\program files\\nu\\bin\\nu.exe',
@@ -60,59 +60,57 @@ export function activate(context: vscode.ExtensionContext) {
60
60
61
61
// brew install location mac
62
62
// intel
63
- "/usr/local/bin/nu " ,
63
+ "/usr/local/bin" ,
64
64
// arm
65
- "/opt/homebrew/bin/nu " ,
65
+ "/opt/homebrew/bin" ,
66
66
67
67
// native package manager install location
68
- "/usr/bin/nu" ,
68
+ // standard location should be in `PATH` env var
69
+ //"/usr/bin/nu",
69
70
] ;
70
71
71
- let found_nushell_path = "" ;
72
- const home = os . homedir ( ) ;
73
-
74
- for ( const cur_val of pathsToCheck ) {
75
- // console.log("Inspecting location: " + cur_val);
76
- let constructed_file = "" ;
77
- if ( cur_val . startsWith ( "~/scoop" ) ) {
78
- // console.log("Found scoop: " + cur_val);
79
- const p = path . join ( home , cur_val . slice ( 1 ) ) ;
80
- // console.log("Expanded ~: " + p);
81
- const file = glob . sync ( p , "debug" ) . toString ( ) ;
82
- // console.log("Glob for files: " + file);
83
-
84
- if ( file ) {
85
- // console.log("Found some file: " + file);
86
- // if there are slashes, reverse them to back slashes
87
- constructed_file = file . replace ( / \/ / g, "\\" ) ;
72
+ const found_nushell_path = which . sync ( "nu" , {
73
+ nothrow : true ,
74
+ path : pathsToCheck . join ( path . delimiter ) ,
75
+ } ) ;
76
+
77
+ if ( found_nushell_path == null ) {
78
+ console . log (
79
+ "Nushell not found in env:PATH or any of the heuristic locations."
80
+ ) ;
81
+ // use an async arrow funciton to use `await` inside
82
+ return ( async ( ) => {
83
+ if (
84
+ ( await vscode . window . showErrorMessage (
85
+ "We cannot find a nushell executable in your path or pre-defined locations" ,
86
+ "install from website"
87
+ ) ) &&
88
+ ( await vscode . env . openExternal (
89
+ vscode . Uri . parse ( "https://www.nushell.sh/" )
90
+ ) ) &&
91
+ ( await vscode . window . showInformationMessage (
92
+ "after you install nushell, you might need to reload vscode" ,
93
+ "reload now"
94
+ ) )
95
+ ) {
96
+ vscode . commands . executeCommand ( "workbench.action.reloadWindow" ) ;
88
97
}
89
- } else if ( cur_val . startsWith ( "~" ) ) {
90
- constructed_file = path . join ( home , cur_val . slice ( 1 ) ) ;
91
- // console.log("Found ~, constructing path: " + constructed_file);
92
- } else {
93
- constructed_file = cur_val ;
94
- }
95
-
96
- if ( fs . existsSync ( constructed_file ) ) {
97
- // console.log("File exists, returning: " + constructed_file);
98
- found_nushell_path = constructed_file ;
99
- break ;
100
- } else {
101
- // console.log("File not found: " + constructed_file);
102
- }
98
+ // user has already seen error messages, but they didn't click through
99
+ // return a promise that never resolve to supress the confusing error
100
+ return await new Promise ( ( ) => undefined ) ;
101
+ } ) ( ) ;
103
102
}
104
103
105
- if ( found_nushell_path . length > 0 ) {
106
- return {
107
- options : {
108
- name : "Nushell" ,
109
- shellPath : found_nushell_path ,
110
- } ,
111
- } ;
112
- } else {
113
- console . log ( "Nushell not found, returning undefined" ) ;
114
- return undefined ;
115
- }
104
+ return {
105
+ options : {
106
+ name : "Nushell" ,
107
+ shellPath : found_nushell_path ,
108
+ iconPath : vscode . Uri . joinPath (
109
+ context . extensionUri ,
110
+ "assets/nu.svg"
111
+ ) ,
112
+ } ,
113
+ } ;
116
114
} ,
117
115
} )
118
116
) ;
0 commit comments