@@ -54,6 +54,7 @@ def launch_shell(
5454 use_profiles : bool ,
5555 * ,
5656 command : tuple [str , ...] | None = None ,
57+ process_callback = None ,
5758) -> int :
5859 """Launch a shell with a custom prompt indicating the exporter type.
5960
@@ -62,6 +63,7 @@ def launch_shell(
6263 context: The context of the shell (e.g. "local" or exporter name)
6364 allow: List of allowed drivers
6465 unsafe: Whether to allow drivers outside of the allow list
66+ process_callback: Optional callback to receive the process object before waiting
6567 """
6668
6769 shell = os .environ .get ("SHELL" , "bash" )
@@ -74,6 +76,8 @@ def launch_shell(
7476
7577 if command :
7678 process = Popen (command , stdin = sys .stdin , stdout = sys .stdout , stderr = sys .stderr , env = common_env )
79+ if process_callback :
80+ process_callback (process )
7781 return process .wait ()
7882
7983 if shell_name .endswith ("bash" ):
@@ -85,6 +89,8 @@ def launch_shell(
8589 if not use_profiles :
8690 cmd .extend (["--norc" , "--noprofile" ])
8791 process = Popen (cmd , stdin = sys .stdin , stdout = sys .stdout , stderr = sys .stderr , env = env )
92+ if process_callback :
93+ process_callback (process )
8894 return process .wait ()
8995
9096 elif shell_name == "fish" :
@@ -103,6 +109,8 @@ def launch_shell(
103109 )
104110 cmd = [shell , "--init-command" , fish_fn ]
105111 process = Popen (cmd , stdin = sys .stdin , stdout = sys .stdout , stderr = sys .stderr , env = common_env )
112+ if process_callback :
113+ process_callback (process )
106114 return process .wait ()
107115
108116 elif shell_name == "zsh" :
@@ -120,8 +128,12 @@ def launch_shell(
120128 cmd .extend (["-o" , "inc_append_history" , "-o" , "share_history" ])
121129
122130 process = Popen (cmd , stdin = sys .stdin , stdout = sys .stdout , stderr = sys .stderr , env = env )
131+ if process_callback :
132+ process_callback (process )
123133 return process .wait ()
124134
125135 else :
126136 process = Popen ([shell ], stdin = sys .stdin , stdout = sys .stdout , stderr = sys .stderr , env = common_env )
137+ if process_callback :
138+ process_callback (process )
127139 return process .wait ()
0 commit comments