@@ -73,6 +73,30 @@ fn enumerate_shells() -> Vec<Shell> {
7373 ]
7474}
7575
76+ /// Builds the shell source lines for the post-install message, showing only
77+ /// shells that are available on the current system. Shells sharing the same
78+ /// env file are grouped onto one line (e.g. sh/bash/zsh all use `env`).
79+ pub ( crate ) fn build_source_env_lines ( process : & Process ) -> String {
80+ let mut groups = Vec :: < ( String , Vec < & ' static str > ) > :: new ( ) ;
81+ for shell in get_available_shells ( process) {
82+ let Ok ( src) = shell. source_string ( process) else {
83+ continue ;
84+ } ;
85+ if let Some ( names) = groups
86+ . iter_mut ( )
87+ . find_map ( |( s, names) | ( * s == src) . then_some ( names) )
88+ {
89+ names. push ( shell. name ( ) ) ;
90+ } else {
91+ groups. push ( ( src, vec ! [ shell. name( ) ] ) ) ;
92+ }
93+ }
94+ groups
95+ . into_iter ( )
96+ . map ( |( src, names) | format ! ( " {} # For {}\n " , src, names. join( "/" ) ) )
97+ . collect ( )
98+ }
99+
76100pub ( crate ) fn get_available_shells ( process : & Process ) -> impl Iterator < Item = Shell > + ' _ {
77101 enumerate_shells ( )
78102 . into_iter ( )
@@ -84,6 +108,9 @@ pub(crate) trait UnixShell {
84108 // heuristic should be used, assuming shells exist if any traces do.
85109 fn does_exist ( & self , process : & Process ) -> bool ;
86110
111+ // Returns the display name of the shell, used in post-install messages.
112+ fn name ( & self ) -> & ' static str ;
113+
87114 // Gives all rcfiles of a given shell that Rustup is concerned with.
88115 // Used primarily in checking rcfiles for cleanup.
89116 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > ;
@@ -128,6 +155,10 @@ impl UnixShell for Posix {
128155 true
129156 }
130157
158+ fn name ( & self ) -> & ' static str {
159+ "sh/ash/dash/pdksh"
160+ }
161+
131162 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
132163 match process. home_dir ( ) {
133164 Some ( dir) => vec ! [ dir. join( ".profile" ) ] ,
@@ -149,6 +180,10 @@ impl UnixShell for Bash {
149180 !self . update_rcs ( process) . is_empty ( )
150181 }
151182
183+ fn name ( & self ) -> & ' static str {
184+ "bash"
185+ }
186+
152187 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
153188 // Bash also may read .profile, however Rustup already includes handling
154189 // .profile as part of POSIX and always does setup for POSIX shells.
@@ -197,6 +232,10 @@ impl UnixShell for Zsh {
197232 || utils:: find_cmd ( & [ "zsh" ] , process) . is_some ( )
198233 }
199234
235+ fn name ( & self ) -> & ' static str {
236+ "zsh"
237+ }
238+
200239 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
201240 [ Zsh :: zdotdir ( process) . ok ( ) , process. home_dir ( ) ]
202241 . iter ( )
@@ -229,6 +268,10 @@ impl UnixShell for Fish {
229268 || utils:: find_cmd ( & [ "fish" ] , process) . is_some ( )
230269 }
231270
271+ fn name ( & self ) -> & ' static str {
272+ "fish"
273+ }
274+
232275 // > "$XDG_CONFIG_HOME/fish/conf.d" (or "~/.config/fish/conf.d" if that variable is unset) for the user
233276 // from <https://github.com/fish-shell/fish-shell/issues/3170#issuecomment-228311857>
234277 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
@@ -278,6 +321,10 @@ impl UnixShell for Nu {
278321 || utils:: find_cmd ( & [ "nu" ] , process) . is_some ( )
279322 }
280323
324+ fn name ( & self ) -> & ' static str {
325+ "nushell"
326+ }
327+
281328 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
282329 let mut paths = vec ! [ ] ;
283330
@@ -329,6 +376,10 @@ impl UnixShell for Tcsh {
329376 || utils:: find_cmd ( & [ "tcsh" ] , process) . is_some ( )
330377 }
331378
379+ fn name ( & self ) -> & ' static str {
380+ "tcsh"
381+ }
382+
332383 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
333384 let mut paths = vec ! [ ] ;
334385
@@ -378,6 +429,10 @@ impl UnixShell for Pwsh {
378429 || utils:: find_cmd ( & [ "pwsh" ] , process) . is_some ( )
379430 }
380431
432+ fn name ( & self ) -> & ' static str {
433+ "pwsh"
434+ }
435+
381436 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
382437 let mut paths = vec ! [ ] ;
383438
@@ -453,6 +508,10 @@ impl UnixShell for Xonsh {
453508 process. var ( "XONSHRC" ) . is_ok ( ) || utils:: find_cmd ( & [ "xonsh" ] , process) . is_some ( )
454509 }
455510
511+ fn name ( & self ) -> & ' static str {
512+ "xonsh"
513+ }
514+
456515 fn rcfiles ( & self , process : & Process ) -> Vec < PathBuf > {
457516 let mut paths = vec ! [ ] ;
458517
0 commit comments