@@ -77,6 +77,7 @@ fn enumerate_shells() -> Vec<Shell> {
7777 Box :: new( Bash ) ,
7878 Box :: new( Zsh ) ,
7979 Box :: new( Fish ) ,
80+ Box :: new( Nu ) ,
8081 ]
8182}
8283
@@ -92,7 +93,7 @@ pub(crate) trait UnixShell {
9293 fn does_exist ( & self , process : & Process ) -> bool ;
9394
9495 // Gives all rcfiles of a given shell that Rustup is concerned with.
95- // Used primarily in checking rcfiles for cleanup.
96+ // Used primarily in checking rcfiles c
9697 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > ;
9798
9899 // Gives rcs that should be written to.
@@ -255,6 +256,60 @@ impl UnixShell for Fish {
255256 }
256257}
257258
259+ struct Nu ;
260+
261+ impl UnixShell for Nu {
262+ fn does_exist ( & self , process : & Process ) -> bool {
263+ // nu has to either be the shell or be callable for nu setup.
264+ matches ! ( process. var( "SHELL" ) , Ok ( sh) if sh. contains( "nu" ) )
265+ || utils:: find_cmd ( & [ "nu" ] , process) . is_some ( )
266+ }
267+
268+ fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
269+ let p0: Vec < _ > = process
270+ . var ( "XDG_CONFIG_HOME" )
271+ . ok ( )
272+ . iter ( )
273+ . flat_map ( |p| {
274+ let path = PathBuf :: from ( p) . join ( "nushell/" ) ;
275+ [ path. join ( "env.nu" ) , path. join ( "config.nu" ) ]
276+ } )
277+ . collect ( ) ;
278+
279+ let p1: Vec < _ > = process
280+ . home_dir ( )
281+ . iter ( )
282+ . flat_map ( |p| {
283+ let path = PathBuf :: from ( p) . join ( ".config/nushell/" ) ;
284+ [ path. join ( "env.nu" ) , path. join ( "config.nu" ) ]
285+ } )
286+ . collect ( ) ;
287+
288+ [ p0, p1] . concat ( )
289+ }
290+
291+ fn update_rcs ( & self , process : & Process ) -> Vec < PathBuf > {
292+ let rcs = self . rcfiles ( process) ;
293+ if rcs. len ( ) == 4 {
294+ // The first two rcfile takes precedence(XDG_CONFIG_HOME).
295+ rcs[ 0 ..2 ] . to_vec ( )
296+ } else {
297+ rcs
298+ }
299+ }
300+
301+ fn env_script ( & self ) -> ShellScript {
302+ ShellScript {
303+ name : "env.nu" ,
304+ content : include_str ! ( "env.nu" ) ,
305+ }
306+ }
307+
308+ fn source_string ( & self , process : & Process ) -> Result < String > {
309+ Ok ( format ! ( r#"source "{}/env.nu""# , cargo_home_str( process) ?) )
310+ }
311+ }
312+
258313pub ( crate ) fn legacy_paths ( process : & Process ) -> impl Iterator < Item = PathBuf > + ' _ {
259314 let zprofiles = Zsh :: zdotdir ( process)
260315 . into_iter ( )
0 commit comments