@@ -576,20 +576,25 @@ pub(crate) enum ShowEnvFormat {
576576 Pwsh ,
577577 /// Each key-value: `set {key}={value}`, where `{value}` is escaped using [`shell_escape::windows::escape`].
578578 Cmd ,
579+ /// Each key-value: `setenv {key} '{value}'`, where `{value}` is escaped using [`shell_escape::unix::escape`].
580+ Csh ,
579581 /// Each key-value: `set -gx {key}={value}`, where `{value}` is escaped using [`shell_escape::unix::escape`].
580582 Fish ,
581583}
582584
583585impl ShowEnvFormat {
584586 #[ allow( clippy:: fn_params_excessive_bools) ]
585- pub ( crate ) fn new ( sh : bool , pwsh : bool , cmd : bool , fish : bool ) -> Result < Self > {
587+ pub ( crate ) fn new ( sh : bool , pwsh : bool , cmd : bool , csh : bool , fish : bool ) -> Result < Self > {
586588 Ok ( if sh {
587589 if pwsh {
588590 conflicts ( "--sh" , "--pwsh" ) ?;
589591 }
590592 if cmd {
591593 conflicts ( "--sh" , "--cmd" ) ?;
592594 }
595+ if csh {
596+ conflicts ( "--sh" , "--csh" ) ?;
597+ }
593598 if fish {
594599 conflicts ( "--sh" , "--fish" ) ?;
595600 }
@@ -598,15 +603,26 @@ impl ShowEnvFormat {
598603 if cmd {
599604 conflicts ( "--pwsh" , "--cmd" ) ?;
600605 }
606+ if csh {
607+ conflicts ( "--pwsh" , "--csh" ) ?;
608+ }
601609 if fish {
602610 conflicts ( "--pwsh" , "--fish" ) ?;
603611 }
604612 ShowEnvFormat :: Pwsh
605613 } else if cmd {
614+ if csh {
615+ conflicts ( "--cmd" , "--csh" ) ?;
616+ }
606617 if fish {
607618 conflicts ( "--cmd" , "--fish" ) ?;
608619 }
609620 ShowEnvFormat :: Cmd
621+ } else if csh {
622+ if fish {
623+ conflicts ( "--csh" , "--fish" ) ?;
624+ }
625+ ShowEnvFormat :: Csh
610626 } else if fish {
611627 ShowEnvFormat :: Fish
612628 } else {
@@ -634,6 +650,15 @@ impl ShowEnvFormat {
634650 ShowEnvFormat :: Cmd => {
635651 writeln ! ( writer, "set {key}={}" , escape:: cmd( value. into( ) ) )
636652 }
653+ ShowEnvFormat :: Csh => {
654+ // TODO: https://en.wikipedia.org/wiki/C_shell#Quoting_and_escaping
655+ let value = escape:: sh ( value. into ( ) ) ;
656+ if value. starts_with ( '"' ) || value. starts_with ( '\'' ) {
657+ writeln ! ( writer, "setenv {key} {value}" )
658+ } else {
659+ writeln ! ( writer, "setenv {key} '{value}'" )
660+ }
661+ }
637662 ShowEnvFormat :: Fish => {
638663 // TODO: https://fishshell.com/docs/current/language.html#quotes
639664 writeln ! ( writer, "set -gx {key}={}" , escape:: sh( value. into( ) ) )
@@ -781,6 +806,7 @@ impl Args {
781806 let mut sh = false ;
782807 let mut pwsh = false ;
783808 let mut cmd = false ;
809+ let mut csh = false ;
784810 let mut fish = false ;
785811
786812 // options ambiguous between nextest-related and others
@@ -994,6 +1020,7 @@ impl Args {
9941020 parse_flag ! ( pwsh) ;
9951021 }
9961022 Long ( "cmd" ) => parse_flag ! ( cmd) ,
1023+ Long ( "csh" ) => parse_flag ! ( csh) ,
9971024 Long ( "fish" ) => parse_flag ! ( fish) ,
9981025
9991026 // ambiguous between nextest-related and others will be handled later
@@ -1099,11 +1126,15 @@ impl Args {
10991126 // Handle options specific to certain subcommands.
11001127 // show-env specific
11011128 let show_env_format = match subcommand {
1102- Subcommand :: ShowEnv => ShowEnvFormat :: new ( sh, pwsh, cmd, fish) ?,
1129+ Subcommand :: ShowEnv => ShowEnvFormat :: new ( sh, pwsh, cmd, csh , fish) ?,
11031130 _ => {
1104- for ( passed, flag) in
1105- [ ( sh, "--sh" ) , ( pwsh, "--pwsh" ) , ( cmd, "--cmd" ) , ( fish, "--fish" ) ]
1106- {
1131+ for ( passed, flag) in [
1132+ ( sh, "--sh" ) ,
1133+ ( pwsh, "--pwsh" ) ,
1134+ ( cmd, "--cmd" ) ,
1135+ ( csh, "--csh" ) ,
1136+ ( fish, "--fish" ) ,
1137+ ] {
11071138 if passed {
11081139 specific_flag ( flag, subcommand, & [ "show-env" ] ) ?;
11091140 }
0 commit comments