@@ -20,6 +20,10 @@ struct Options {
2020 /// The path to the file that should be executed
2121 file : Option < PathBuf > ,
2222
23+ /// Continue in interactive mode after the file has been executed
24+ #[ clap( long) ]
25+ interact : bool ,
26+
2327 #[ clap( short, long) ]
2428 debug : bool ,
2529}
@@ -30,7 +34,7 @@ fn init_state() -> ShellState {
3034 ShellState :: new ( env_vars, & cwd, commands:: get_commands ( ) )
3135}
3236
33- async fn interactive ( ) -> miette:: Result < ( ) > {
37+ async fn interactive ( state : Option < ShellState > ) -> miette:: Result < ( ) > {
3438 let config = Config :: builder ( )
3539 . history_ignore_space ( true )
3640 . completion_type ( CompletionType :: List )
@@ -46,7 +50,7 @@ async fn interactive() -> miette::Result<()> {
4650 let helper = helper:: ShellPromptHelper :: default ( ) ;
4751 rl. set_helper ( Some ( helper) ) ;
4852
49- let mut state = init_state ( ) ;
53+ let mut state = state . unwrap_or_else ( init_state ) ;
5054
5155 let home = dirs:: home_dir ( ) . ok_or ( miette:: miette!( "Couldn't get home directory" ) ) ?;
5256 let history_file: PathBuf = [ home. as_path ( ) , Path :: new ( ".shell_history" ) ]
@@ -151,8 +155,11 @@ async fn main() -> miette::Result<()> {
151155 return Ok ( ( ) ) ;
152156 }
153157 execute ( & script_text, & mut state) . await ?;
158+ if options. interact {
159+ interactive ( Some ( state) ) . await ?;
160+ }
154161 } else {
155- interactive ( ) . await ?;
162+ interactive ( None ) . await ?;
156163 }
157164
158165 Ok ( ( ) )
0 commit comments